From 04feb84192e4c8d89ad7906c7ca40b908f41e933 Mon Sep 17 00:00:00 2001 From: wallace Date: Fri, 28 Nov 2025 14:49:56 +0900 Subject: [PATCH] =?UTF-8?q?=EB=B9=84=EB=B0=80=EB=B2=88=ED=98=B8=20?= =?UTF-8?q?=EB=B3=80=EA=B2=BD=20=EC=88=98=EC=A0=952?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/app/lib/apiService.ts | 6 +- src/app/menu/ChangePasswordModal.tsx | 100 +++++++++++++++++++++++++-- 2 files changed, 99 insertions(+), 7 deletions(-) diff --git a/src/app/lib/apiService.ts b/src/app/lib/apiService.ts index c230495..ebd64ed 100644 --- a/src/app/lib/apiService.ts +++ b/src/app/lib/apiService.ts @@ -228,17 +228,17 @@ class ApiService { async verifyPasswordResetCode(email: string, code: string) { return this.request('/auth/password/confirm', { method: 'POST', - body: { email, code }, + body: { email, emailCode: code }, }); } /** * 비밀번호 재설정 */ - async resetPassword(email: string, code: string, newPassword: string, confirmPassword: string) { + async resetPassword(email: string, emailCode: string, newPassword: string, newPasswordConfirm: string) { return this.request('/auth/password/reset', { method: 'POST', - body: { email, code, newPassword, confirmPassword }, + body: { email, emailCode, newPassword, newPasswordConfirm }, }); } diff --git a/src/app/menu/ChangePasswordModal.tsx b/src/app/menu/ChangePasswordModal.tsx index f73f5c1..e551248 100644 --- a/src/app/menu/ChangePasswordModal.tsx +++ b/src/app/menu/ChangePasswordModal.tsx @@ -1,6 +1,7 @@ 'use client'; import { useEffect, useState } from "react"; +import { useRouter } from "next/navigation"; import ModalCloseSvg from "../svgs/closexsvg"; import apiService from "../lib/apiService"; @@ -14,6 +15,7 @@ type Props = { }; export default function ChangePasswordModal({ open, onClose, onSubmit, showVerification = false, devVerificationState, initialEmail }: Props) { + const router = useRouter(); const [email, setEmail] = useState(initialEmail || ""); const [code, setCode] = useState(""); const [newPassword, setNewPassword] = useState(""); @@ -25,6 +27,7 @@ export default function ChangePasswordModal({ open, onClose, onSubmit, showVerif const [isVerified, setIsVerified] = useState(false); const [isSending, setIsSending] = useState(false); const [isVerifying, setIsVerifying] = useState(false); + const [showSuccessModal, setShowSuccessModal] = useState(false); const hasError = !!error; // initialEmail이 변경되면 email state 업데이트 @@ -71,9 +74,18 @@ export default function ChangePasswordModal({ open, onClose, onSubmit, showVerif } }, [devVerificationState]); - if (!open) return null; + const handleLoginClick = () => { + // 토큰 삭제 (로그아웃) + if (typeof window !== 'undefined') { + localStorage.removeItem('token'); + document.cookie = 'token=; path=/; expires=Thu, 01 Jan 1970 00:00:00 GMT'; + } + // 로그인 페이지로 이동 + router.push('/login'); + onClose(); + }; - const handleSubmit = () => { + const handleSubmit = async () => { setError(null); if (requireCode) { if (!code) { @@ -89,10 +101,87 @@ export default function ChangePasswordModal({ open, onClose, onSubmit, showVerif setError("새 비밀번호가 일치하지 않습니다."); return; } - onSubmit?.({ email, code: requireCode ? code : undefined, newPassword }); + if (!email.trim()) { + setError("이메일을 입력해 주세요."); + return; + } + if (requireCode && !code.trim()) { + setError("인증번호를 입력해 주세요."); + return; + } + + try { + await apiService.resetPassword(email, code, newPassword, confirmPassword); + onSubmit?.({ email, code: requireCode ? code : undefined, newPassword }); + setShowSuccessModal(true); + } catch (err) { + setError(err instanceof Error ? err.message : "비밀번호 변경에 실패했습니다."); + } + }; + + const handleCancel = () => { + // 모든 상태 초기화 + setEmail(initialEmail || ""); + setCode(""); + setNewPassword(""); + setConfirmPassword(""); + setError(null); + setRequireCode(showVerification); + setIsCodeSent(showVerification); + setIsVerified(false); + setIsSending(false); + setIsVerifying(false); onClose(); }; + // 완료 팝업은 open prop과 관계없이 표시 + if (showSuccessModal) { + return ( +
+
+ {/* header */} +
+ +
+ + {/* body */} +
+

+ 비밀번호 변경이 완료됐습니다. +

+

+ 새로운 비밀번호로 다시 로그인 해주세요. +

+
+ + {/* footer */} +
+ +
+
+
+ ); + } + + if (!open) return null; + return (