-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #59 from epigram5-9/feat/FE-69
FE-66 ✨ 회원가입 페이지 api
- Loading branch information
Showing
5 changed files
with
89 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import type { PostSignUpRequestType, PostAuthResponseType } from '@/schema/auth'; | ||
import httpClient from '.'; | ||
|
||
// TODO: signin, signup 단어가 비슷해 login, register로 바꿀 예정 | ||
|
||
const postSignup = async (request: PostSignUpRequestType): Promise<PostAuthResponseType> => { | ||
const response = await httpClient.post('/auth/signUp', request); | ||
return response.data; | ||
}; | ||
|
||
export default postSignup; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
import postSignup from '@/apis/auth'; | ||
import { toast } from '@/components/ui/use-toast'; | ||
import { useMutation } from '@tanstack/react-query'; | ||
import { useRouter } from 'next/router'; | ||
import { isAxiosError } from 'axios'; | ||
|
||
const useRegisterMutation = () => { | ||
const router = useRouter(); | ||
|
||
return useMutation({ | ||
mutationFn: postSignup, | ||
onSuccess: (data) => { | ||
localStorage.setItem('accessToken', data.accessToken); | ||
localStorage.setItem('refreshToken', data.refreshToken); | ||
router.push('/'); | ||
}, | ||
onError: (error) => { | ||
if (!isAxiosError(error)) { | ||
toast({ | ||
description: '네트워크 오류가 발생했습니다. 인터넷 연결을 확인해주세요.', | ||
className: 'border-state-error text-state-error font-semibold', | ||
}); | ||
return; | ||
} | ||
|
||
const { status } = error.response || {}; | ||
|
||
if (status === 400) { | ||
toast({ | ||
description: '이미 사용중인 이메일입니다.', | ||
className: 'border-state-error text-state-error font-semibold', | ||
}); | ||
return; | ||
} | ||
|
||
if (status === 500) { | ||
toast({ | ||
description: '이미 존재하는 닉네임입니다.', | ||
className: 'border-state-error text-state-error font-semibold', | ||
}); | ||
return; | ||
} | ||
|
||
toast({ | ||
description: '알 수 없는 오류가 발생했습니다. 잠시 후 다시 시도해주세요.', | ||
className: 'border-state-error text-state-error font-semibold', | ||
}); | ||
}, | ||
}); | ||
}; | ||
|
||
export default useRegisterMutation; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters