diff --git a/src/apis/hooks/useSignUp.ts b/src/apis/hooks/useSignUp.ts index 3750fc9c..56a19fbe 100644 --- a/src/apis/hooks/useSignUp.ts +++ b/src/apis/hooks/useSignUp.ts @@ -7,19 +7,13 @@ interface User { password: string } -interface SignUpSuccess { +interface SignUp { success: boolean } -interface SignUpFail { - status: string - errorCode: string - message: string -} - const useSignUp = () => { const signUp = async (user: User) => { - return await apiClient.post('/sign-up', user) + return await apiClient.post('/sign-up', user) } return useMutation({ mutationFn: signUp }) diff --git a/src/components/Input/index.tsx b/src/components/Input/index.tsx index f52f7171..eda0ac40 100644 --- a/src/components/Input/index.tsx +++ b/src/components/Input/index.tsx @@ -30,10 +30,10 @@ const Input = ({ return (
-
+
{INPUT_TYPE[type].TITLE}
{message && ( @@ -46,7 +46,7 @@ const Input = ({ { useNameCheck() const { password, - passwordConfirm, passwordFailMessage, + passwordConfirm, passwordConfirmFailMessage, handlePasswordChange, handlePasswordConfirmChange, @@ -27,6 +28,10 @@ const SingUpPage = () => { e.preventDefault() if ( + !name || + !email || + !password || + !passwordConfirm || emailFailMessage || nameFailMessage || passwordFailMessage || @@ -38,19 +43,16 @@ const SingUpPage = () => { signUp( { email, name, password }, { - onSuccess: ({ data }) => { - if ('status' in data && data.status === 'CONFLICT') { - if (data.errorCode === 'EXIST_SAME_NAME') { - setNameFailMessage(data.message) - } - if (data.errorCode === 'EXIST_SAME_EMAIL') { - setEmailFailMessage(data.message) + onSuccess: () => navigate('/'), + onError: (error) => { + if (isAxiosError(error)) { + const message = error.response?.data.message + if (message.includes('이메일')) { + setEmailFailMessage(message) + } else { + setNameFailMessage(message) } - - return } - - navigate('/') }, }, ) @@ -91,7 +93,6 @@ const SingUpPage = () => { message={passwordConfirmFailMessage} />