Skip to content

Commit d7a1363

Browse files
authored
Merge pull request #132 from ezcode-my/chore/apply-form
[feat] apply form
2 parents 7258d4a + 9817aec commit d7a1363

File tree

8 files changed

+190
-293
lines changed

8 files changed

+190
-293
lines changed

src/app/testinput/page.tsx

Lines changed: 0 additions & 45 deletions
This file was deleted.

src/entities/auth/model/authZodSchemas.ts

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,25 @@
11
import { M } from '@/shared/lib/zod/messages';
2-
import { EMAIL, Name, PASSWORD, PASSWORD_CHECK } from '@/shared/lib/zod/primitives';
2+
import { EMAIL, NAME, PASSWORD, PASSWORD_CHECK } from '@/shared/lib/zod/primitives';
33
import { z } from 'zod';
44

5+
/**로그인 스키마 */
56
/**자동 타입 추론 */
6-
export type TAuthSchemaRegister = z.infer<typeof AUTH_ZOD_SCHEMA>;
7+
export type TSigninSchemaRegister = z.infer<typeof SIGNIN_ZOD_SCHEMA>;
78

8-
/**@notice validate 작성 , input에서 사용할 name을 레지스터 key 로 등록해주세요 */
9-
/**@description - 해당 스키마는 임의로 작성, 기획에 따라 사용시 확인후 수정 부탁드려요*/
9+
export const SIGNIN_ZOD_SCHEMA = z.object({
10+
email: EMAIL,
11+
password: PASSWORD,
12+
});
13+
14+
/**-------------------------------------------------------------------------*/
15+
16+
/**회원 가입 스키마 */
17+
/**자동 타입 추론 */
18+
export type TSignupSchemaRegister = z.infer<typeof SIGNUP_ZOD_SCHEMA>;
1019

11-
export const AUTH_ZOD_SCHEMA = z
20+
export const SIGNUP_ZOD_SCHEMA = z
1221
.object({
13-
name: Name,
22+
name: NAME,
1423
email: EMAIL,
1524
password: PASSWORD,
1625
passwordCheck: PASSWORD_CHECK,
@@ -19,8 +28,3 @@ export const AUTH_ZOD_SCHEMA = z
1928
path: ['passwordCheck'],
2029
message: M.PASSWORD_CHECK.INCORRECT_PASSWORD_CHECK,
2130
});
22-
23-
export const TEST_SCHEMA = z.object({
24-
email: EMAIL,
25-
password: PASSWORD,
26-
});

src/features/auth/hooks/useLogin.ts

Lines changed: 3 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
'use client';
2-
import { ChangeEvent } from 'react';
32
import { useState } from 'react';
43
import { useRouter } from 'next/navigation';
54

@@ -16,36 +15,15 @@ import { toast } from 'sonner';
1615
const useLogin = (onLoginSuccess?: () => void) => {
1716
const { setUser } = useUserStore((state) => state);
1817
const router = useRouter();
19-
/** 로그인 정보 */
20-
const [loginInfo, setLoginInfo] = useState({
21-
email: '',
22-
password: '',
23-
});
24-
2518
/** 비밀번호 표시 정보 */
2619
const [isPasswordVisible, setIsPasswordVisible] = useState(false);
27-
28-
/** 로그인 에러 정보*/
29-
// const [errorMessage, setErrorMessage] = useState('');
30-
31-
/** 로그인 정보 변경 함수 */
32-
const handleChangeLoginInfo = (e: ChangeEvent<HTMLInputElement>) => {
33-
const { name, value } = e.target;
34-
setLoginInfo((prev) => ({ ...prev, [name]: value }));
35-
};
36-
3720
/** 비밀번호 표시 함수 */
3821
const handlePasswordVisible = () => {
3922
setIsPasswordVisible((prev) => !prev);
4023
};
4124

42-
/** 로그인 에러 함수 */
43-
// const handleSignInError = (pError: string) => {
44-
// setErrorMessage(pError);
45-
// };
46-
4725
/** 로그인 클릭 함수 */
48-
const handleSignInClick = async () => {
26+
const handleSignInClick = async (data: Record<string, unknown>) => {
4927
try {
5028
// setErrorMessage('');
5129
// const result = await signIn('credentials', {
@@ -62,8 +40,8 @@ const useLogin = (onLoginSuccess?: () => void) => {
6240
const result = await ApiHelper.post<{ accessToken: string; refreshToken: string }>(
6341
API_URL.AUTH.SIGN_IN,
6442
{
65-
email: loginInfo.email,
66-
password: loginInfo.password,
43+
email: data.email,
44+
password: data.password,
6745
}
6846
);
6947
if (result.data.status !== 200) {
@@ -89,7 +67,6 @@ const useLogin = (onLoginSuccess?: () => void) => {
8967
sameSite: 'lax', // 기본 보안
9068
});
9169
const response = await ApiHelper.get<IMyInfo>(API_URL.MYPAGE.USER_INFO);
92-
console.log('weafwefwaef', response);
9370
if (response.data.status === 200) {
9471
setUser(response.data.result);
9572
}
@@ -121,8 +98,6 @@ const useLogin = (onLoginSuccess?: () => void) => {
12198
};
12299

123100
return {
124-
loginInfo,
125-
handleChangeLoginInfo,
126101
handleSignInClick,
127102
handlePasswordVisible,
128103
isPasswordVisible,

src/features/auth/hooks/useSignUp.ts

Lines changed: 46 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
'use client';
22
import { API_CONSTANTS } from '@/api/constants/api.constants';
33
import { useSignUpMutation } from '@/entities/auth/model/mutation/auth.mutation';
4-
import { ChangeEvent, useState } from 'react';
4+
import { useState } from 'react';
55
import { useAuthStore } from '../store/authSlice';
66
import { useShallow } from 'zustand/shallow';
77
import { toast } from 'sonner';
@@ -20,17 +20,17 @@ const useSignUp = () => {
2020
const { mutateAsync } = useSignUpMutation();
2121

2222
/** 회원가입 정보 */
23-
const [signUpInfo, setSignUpInfo] = useState({
24-
email: '',
25-
password: '',
26-
passwordConfirm: '',
27-
username: '',
28-
nickname: '',
29-
age: 0,
30-
});
23+
// const [signUpInfo, setSignUpInfo] = useState({
24+
// email: '',
25+
// password: '',
26+
// passwordConfirm: '',
27+
// username: '',
28+
// nickname: '',
29+
// age: 0,
30+
// });
3131

3232
/** 회원가입 에러 메시지 */
33-
const [errorMessage, setErrorMessage] = useState('');
33+
// const [errorMessage, setErrorMessage] = useState('');
3434

3535
/** 비밀번호 보여주기 상태 */
3636
const [showPassword, setShowPassword] = useState(false);
@@ -39,34 +39,29 @@ const useSignUp = () => {
3939
const [showPasswordConfirm, setShowPasswordConfirm] = useState(false);
4040

4141
/** 회원가입 정보 변경 함수 */
42-
const handleChangeSignUpInfo = (e: ChangeEvent<HTMLInputElement>) => {
43-
const { name, value } = e.target;
44-
setSignUpInfo((prev) => ({ ...prev, [name]: value }));
45-
};
42+
// const handleChangeSignUpInfo = (e: ChangeEvent<HTMLInputElement>) => {
43+
// const { name, value } = e.target;
44+
// setSignUpInfo((prev) => ({ ...prev, [name]: value }));
45+
// };
4646

4747
/** 회원가입 에러 함수 */
48-
const handleSignUpError = (pError: string) => {
49-
setErrorMessage(pError);
50-
};
48+
// const handleSignUpError = (pError: string) => {
49+
// setErrorMessage(pError);
50+
// };
5151

5252
/** 회원가입 클릭 함수 */
53-
const handleSignUpClick = async () => {
53+
const handleSignUpClick = async (data: Record<string, unknown>) => {
5454
try {
55-
setErrorMessage('');
56-
const response = await mutateAsync(signUpInfo);
57-
if (response.data.status !== API_CONSTANTS.CODE.CREATED) {
58-
handleSignUpError(response.data.message);
59-
return;
60-
}
55+
// setErrorMessage('');
56+
const response = await mutateAsync({
57+
email: data.email as string,
58+
password: data.password as string,
59+
passwordConfirm: data.passwordCheck as string,
60+
username: data.name as string,
61+
nickname: '',
62+
age: 0,
63+
});
6164
if (response.data.status === API_CONSTANTS.CODE.CREATED) {
62-
setSignUpInfo({
63-
email: '',
64-
password: '',
65-
passwordConfirm: '',
66-
username: '',
67-
nickname: '',
68-
age: 0,
69-
});
7065
toast.success('회원가입에 완료', {
7166
richColors: false,
7267
style: {
@@ -78,12 +73,26 @@ const useSignUp = () => {
7873
},
7974
});
8075
setActiveTab('login');
76+
} else {
77+
toast.error(response.data.message || '로그인에 실패했습니다.', {
78+
richColors: false,
79+
style: {
80+
fontWeight: 'bold',
81+
fontSize: '16px',
82+
},
83+
});
84+
return;
8185
}
8286
} catch (err) {
83-
console.error(err);
87+
toast.error('알 수 없는 오류가 발생했습니다.', {
88+
richColors: false,
89+
style: {
90+
fontWeight: 'bold',
91+
fontSize: '16px',
92+
},
93+
});
8494
}
8595
};
86-
8796
/** 비밀번호 보이기/숨기기 토글 함수 */
8897
const handlePasswordVisible = () => {
8998
setShowPassword(!showPassword);
@@ -92,16 +101,15 @@ const useSignUp = () => {
92101
const handlePasswordConfirmVisible = () => {
93102
setShowPasswordConfirm(!showPasswordConfirm);
94103
};
95-
96104
return {
97-
signUpInfo,
98-
handleChangeSignUpInfo,
105+
// signUpInfo,
106+
// handleChangeSignUpInfo,
99107
handleSignUpClick,
100108
handlePasswordVisible,
101109
handlePasswordConfirmVisible,
102110
showPassword,
103111
showPasswordConfirm,
104-
errorMessage,
112+
// errorMessage,
105113
};
106114
};
107115

0 commit comments

Comments
 (0)