diff --git a/src/constants/formValidationRules.ts b/src/constants/formValidationRules.ts index d695f580..43d9efa7 100644 --- a/src/constants/formValidationRules.ts +++ b/src/constants/formValidationRules.ts @@ -104,6 +104,10 @@ export const USER_AUTH_VALIDATION_RULES = deepFreeze({ required: '비밀번호를 한 번 더 입력해 주세요.', validate: (value: string) => value === password || '비밀번호가 일치하지 않습니다.', }), + NEW_PASSWORD: (currentPassword: string) => ({ + ...USER_AUTH_VALIDATION_RULES.PASSWORD, + validate: (value: string) => value !== currentPassword || '신규 비밀번호가 현재 비밀번호와 동일합니다.', + }), ID: { required: '아이디를 입력해 주세요.', minLength: { diff --git a/src/pages/setting/UserPasswordSettingPage.tsx b/src/pages/setting/UserPasswordSettingPage.tsx index 5529b0b0..fcc8e123 100644 --- a/src/pages/setting/UserPasswordSettingPage.tsx +++ b/src/pages/setting/UserPasswordSettingPage.tsx @@ -20,8 +20,6 @@ export default function UserPasswordSettingPage() { }); const onSubmit = async (data: UpdatePasswordForm) => { - if (watch('password') === watch('newPassword')) return toastError('신규 비밀번호가 현재 비밀번호와 동일합니다.'); - const { checkNewPassword, ...submitData } = data; // ToDo: useAxios 훅을 이용한 네트워크 로직으로 변경 @@ -53,7 +51,7 @@ export default function UserPasswordSettingPage() { label="신규 비밀번호" type="password" errors={errors.newPassword?.message} - register={register('newPassword', USER_AUTH_VALIDATION_RULES.PASSWORD)} + register={register('newPassword', USER_AUTH_VALIDATION_RULES.NEW_PASSWORD(watch('password')))} /> {/* 신규 비밀번호 확인 */}