Skip to content

Commit

Permalink
Formatting: #146 이메일 인증 코드 변수명 및 타입명 변경
Browse files Browse the repository at this point in the history
  • Loading branch information
Yoonyesol committed Sep 25, 2024
1 parent 55e1eb0 commit 1c4ed95
Show file tree
Hide file tree
Showing 7 changed files with 24 additions and 24 deletions.
2 changes: 1 addition & 1 deletion src/mocks/mockData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ type TaskFile = {

export const JWT_TOKEN_DUMMY = 'mocked-header.mocked-payload-4.mocked-signature';

export const emailVerificationCode = '1234';
export const VERIFICATION_CODE_DUMMY = '1234';

export const USER_INFO_DUMMY = {
provider: 'LOCAL',
Expand Down
14 changes: 7 additions & 7 deletions src/mocks/services/authServiceHandler.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import Cookies from 'js-cookie';
import { http, HttpResponse } from 'msw';
import { AUTH_SETTINGS } from '@constants/settings';
import { emailVerificationCode, USER_INFO_DUMMY } from '@mocks/mockData';
import { VERIFICATION_CODE_DUMMY, USER_INFO_DUMMY } from '@mocks/mockData';
import {
EmailVerificationForm,
RequestEmailCode,
Expand Down Expand Up @@ -130,19 +130,19 @@ const authServiceHandler = [

// 이메일 인증 번호 확인 API
http.post(`${BASE_URL}/user/verify/code`, async ({ request }) => {
const { email, code } = (await request.json()) as EmailVerificationForm;
const { email, verificationCode } = (await request.json()) as EmailVerificationForm;

if (email !== USER_INFO_DUMMY.email || code !== emailVerificationCode)
if (email !== USER_INFO_DUMMY.email || verificationCode !== VERIFICATION_CODE_DUMMY)
return HttpResponse.json({ message: '인증번호가 일치하지 않습니다.' }, { status: 401 });

return HttpResponse.json(null, { status: 200 });
}),

// 아이디 찾기 API
http.post(`${BASE_URL}/user/recover/username`, async ({ request }) => {
const { email, code } = (await request.json()) as EmailVerificationForm;
const { email, verificationCode } = (await request.json()) as EmailVerificationForm;

if (code !== emailVerificationCode) {
if (verificationCode !== VERIFICATION_CODE_DUMMY) {
return HttpResponse.json(
{ message: '이메일 인증 번호가 일치하지 않습니다. 다시 확인해 주세요.' },
{ status: 401 },
Expand All @@ -157,11 +157,11 @@ const authServiceHandler = [

// 비밀번호 찾기 API
http.post(`${BASE_URL}/user/recover/password`, async ({ request }) => {
const { username, email, code } = (await request.json()) as SearchPasswordForm;
const { username, email, verificationCode } = (await request.json()) as SearchPasswordForm;

const tempPassword = '!1p2l3nqlz';

if (code !== emailVerificationCode) {
if (verificationCode !== VERIFICATION_CODE_DUMMY) {
return HttpResponse.json(
{ message: '이메일 인증 번호가 일치하지 않습니다. 다시 확인해 주세요.' },
{ status: 401 },
Expand Down
4 changes: 2 additions & 2 deletions src/pages/setting/UserAuthenticatePage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,8 @@ function UserAuthenticatePage() {
{isVerificationRequested && (
<ValidationInput
label="인증번호"
errors={errors.code?.message}
register={register('code', USER_AUTH_VALIDATION_RULES.CERTIFICATION)}
errors={errors.verificationCode?.message}
register={register('verificationCode', USER_AUTH_VALIDATION_RULES.CERTIFICATION)}
/>
)}

Expand Down
6 changes: 3 additions & 3 deletions src/pages/user/SearchIdPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export default function SearchIdPage() {
mode: 'onChange',
defaultValues: {
email: '',
code: '',
verificationCode: '',
},
});
const { handleSubmit, setError, setValue } = methods;
Expand All @@ -33,11 +33,11 @@ export default function SearchIdPage() {

// ToDo: useAxios 훅 적용 후 해당 함수 수정 및 삭제하기
const handleVerificationError = () => {
setError('code', {
setError('verificationCode', {
type: 'manual',
message: '인증번호가 일치하지 않습니다.',
});
setValue('code', '');
setValue('verificationCode', '');
};

// ToDo: useAxios 훅을 이용한 네트워크 로직으로 변경
Expand Down
6 changes: 3 additions & 3 deletions src/pages/user/SearchPasswordPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export default function SearchPasswordPage() {
defaultValues: {
username: '',
email: '',
code: '',
verificationCode: '',
},
});
const { handleSubmit, setError, setValue } = methods;
Expand All @@ -33,11 +33,11 @@ export default function SearchPasswordPage() {

// ToDo: useAxios 훅 적용 후 해당 함수 수정 및 삭제하기
const handleVerificationError = () => {
setError('code', {
setError('verificationCode', {
type: 'manual',
message: '인증번호가 일치하지 않습니다.',
});
setValue('code', '');
setValue('verificationCode', '');
};

// ToDo: useAxios 훅을 이용한 네트워크 로직으로 변경
Expand Down
10 changes: 5 additions & 5 deletions src/pages/user/SignUpPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export default function SignUpPage() {
defaultValues: {
username: null,
email: '',
code: '',
verificationCode: '',
nickname: '',
password: '',
checkPassword: '',
Expand All @@ -32,12 +32,12 @@ export default function SignUpPage() {

// form 전송 함수
const onSubmit = async (data: UserSignUpForm) => {
const { username, code, checkPassword, profileImageName, ...filteredData } = data;
const { username, verificationCode, checkPassword, profileImageName, ...filteredData } = data;
console.log(data);
// TODO: 폼 제출 로직 수정 필요
try {
// 회원가입 폼
const formData = { ...filteredData, username, code, profileImageName };
const formData = { ...filteredData, username, verificationCode, profileImageName };
const registrationResponse = await axios.post(`http://localhost:8080/api/v1/user/${username}`, formData);
if (registrationResponse.status !== 200) return toastError('회원가입에 실패했습니다. 다시 시도해 주세요.');

Expand Down Expand Up @@ -93,8 +93,8 @@ export default function SignUpPage() {
{isVerificationRequested && (
<ValidationInput
label="인증번호"
errors={methods.formState.errors.code?.message}
register={methods.register('code', USER_AUTH_VALIDATION_RULES.CERTIFICATION)}
errors={methods.formState.errors.verificationCode?.message}
register={methods.register('verificationCode', USER_AUTH_VALIDATION_RULES.CERTIFICATION)}
/>
)}

Expand Down
6 changes: 3 additions & 3 deletions src/types/UserType.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export type UserWithRole = SearchUser & Pick<Role, 'roleName'>;
export type EditUserInfoForm = Omit<User, 'userId' | 'provider'>;

export type UserSignUpForm = Omit<User, 'userId' | 'provider'> & {
code: string;
verificationCode: string;
password: string;
checkPassword: string;
};
Expand All @@ -26,9 +26,9 @@ export type UserSignInForm = Pick<User, 'username'> & {
password: string;
};

export type EmailVerificationForm = Pick<User, 'email'> & { code: string };
export type EmailVerificationForm = Pick<User, 'email'> & { verificationCode: string };

export type SearchPasswordForm = Pick<User, 'username' | 'email'> & { code: string };
export type SearchPasswordForm = Pick<User, 'username' | 'email'> & { verificationCode: string };

export type UpdatePasswordForm = {
password: string;
Expand Down

0 comments on commit 1c4ed95

Please sign in to comment.