@@ -11,6 +11,7 @@ import axios from "@/utils/axios";
1111const FindPage = ( ) => {
1212 const router = useRouter ( ) ;
1313 const [ tab , setTab ] = useState < "id" | "password" > ( "id" ) ;
14+ const [ username , setUsername ] = useState ( "" ) ;
1415 const [ email , setEmail ] = useState ( "" ) ;
1516 const [ foundId , setFoundId ] = useState < string | null > ( null ) ;
1617 const [ showVerification , setShowVerification ] = useState ( false ) ;
@@ -45,7 +46,7 @@ const FindPage = () => {
4546 const handleFindId = async ( ) => {
4647 try {
4748 const res = await axios . post ( "/api/v1/member/find-userId" , { email } ) ;
48- if ( res . data . status === 200 ) {
49+ if ( res . data . status === 0 ) {
4950 setFoundId ( res . data . data ) ;
5051 } else {
5152 alert ( res . data . message || "아이디를 찾을 수 없습니다." ) ;
@@ -56,6 +57,62 @@ const FindPage = () => {
5657 }
5758 } ;
5859
60+ const handleSendResetEmail = async ( ) => {
61+ try {
62+ const res = await axios . post ( "/api/v1/email/reset-certification" , {
63+ username,
64+ email,
65+ } ) ;
66+ if ( res . data . status === 200 ) {
67+ setShowVerification ( true ) ;
68+ } else {
69+ alert ( res . data . message || "이메일 인증 요청 실패" ) ;
70+ }
71+ } catch ( err ) {
72+ console . error ( "이메일 전송 실패" , err ) ;
73+ }
74+ } ;
75+
76+ const handleCheckResetCode = async ( ) => {
77+ try {
78+ const res = await axios . post ( "/api/v1/member/check-certification" , {
79+ username,
80+ email,
81+ certificationNumber : verificationCode ,
82+ } ) ;
83+ if ( res . data . status === 200 ) {
84+ setIsVerified ( true ) ;
85+ setVerificationError ( false ) ;
86+ } else {
87+ setIsVerified ( false ) ;
88+ setVerificationError ( true ) ;
89+ }
90+ } catch ( err ) {
91+ console . error ( "인증 실패" , err ) ;
92+ setIsVerified ( false ) ;
93+ setVerificationError ( true ) ;
94+ }
95+ } ;
96+
97+ const handleResetPassword = async ( ) => {
98+ try {
99+ const res = await axios . post ( "/api/v1/member/reset-password" , {
100+ username,
101+ password : newPassword ,
102+ confirmPassword,
103+ } ) ;
104+ if ( res . data . status === 200 ) {
105+ alert ( "비밀번호가 성공적으로 변경되었습니다." ) ;
106+ router . push ( "/login" ) ;
107+ } else {
108+ alert ( res . data . message || "비밀번호 변경 실패" ) ;
109+ }
110+ } catch ( err ) {
111+ console . error ( "비밀번호 변경 실패" , err ) ;
112+ alert ( "비밀번호 변경 중 오류가 발생했습니다." ) ;
113+ }
114+ } ;
115+
59116 return (
60117 < div className = "flex flex-col items-center w-[390px] pt-[164px] h-[844px] mx-auto p-6" >
61118 < Title pageTitle = "아이디 / 비밀번호 찾기" />
@@ -120,9 +177,9 @@ const FindPage = () => {
120177 label = "아이디"
121178 type = "text"
122179 placeholder = "아이디 입력"
180+ value = { username }
123181 disabled
124182 />
125-
126183 < InputField
127184 label = "변경 비밀번호"
128185 type = "password"
@@ -138,11 +195,20 @@ const FindPage = () => {
138195 value = { confirmPassword }
139196 onChange = { ( e ) => setConfirmPassword ( e . target . value ) }
140197 />
141- < PrimaryButton text = "비밀번호 변경하기" />
198+ < PrimaryButton
199+ text = "비밀번호 변경하기"
200+ onClick = { handleResetPassword }
201+ />
142202 </ div >
143203 ) : (
144204 < div >
145- < InputField label = "아이디" type = "text" placeholder = "아이디 입력" />
205+ < InputField
206+ label = "아이디"
207+ type = "text"
208+ placeholder = "아이디 입력"
209+ value = { username }
210+ onChange = { ( e ) => setUsername ( e . target . value ) }
211+ />
146212 < div className = "w-full flex items-center" >
147213 < InputField
148214 label = "이메일"
@@ -153,7 +219,7 @@ const FindPage = () => {
153219 >
154220 < button
155221 className = "font-bold px-4 py-2 bg-primary text-white rounded-md text-sm whitespace-nowrap"
156- onClick = { ( ) => setShowVerification ( true ) }
222+ onClick = { handleSendResetEmail }
157223 >
158224 인증
159225 </ button >
@@ -182,15 +248,7 @@ const FindPage = () => {
182248 ) }
183249 < button
184250 className = "ml-2 font-bold px-4 py-2 bg-primary text-white rounded-md text-sm whitespace-nowrap"
185- onClick = { ( ) => {
186- if ( verificationCode === "1234" ) {
187- setIsVerified ( true ) ;
188- setVerificationError ( false ) ;
189- } else {
190- setIsVerified ( false ) ;
191- setVerificationError ( true ) ;
192- }
193- } }
251+ onClick = { handleCheckResetCode }
194252 >
195253 확인
196254 </ button >
0 commit comments