-
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 #54 from epigram5-9/fix/FE-29
FE-29 ♻️ 코드 리뷰에 대한 리팩토링
- Loading branch information
Showing
7 changed files
with
50 additions
and
74 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 |
---|---|---|
@@ -1,30 +1,9 @@ | ||
import type { PostSigninRequestType, PostSigninResponseType } from '@/schema/auth'; | ||
import { AxiosError } from 'axios'; | ||
import httpClient from '.'; | ||
|
||
const postSignin = async (request: PostSigninRequestType): Promise<PostSigninResponseType> => { | ||
try { | ||
const response = await httpClient.post('/auth/signIn', request); | ||
return response.data; | ||
} catch (error) { | ||
if (error instanceof AxiosError) { | ||
// Axios 에러인 경우 | ||
const axiosError = error as AxiosError; | ||
if (axiosError.response) { | ||
// 서버에서 응답이 온 경우 (예: 4xx, 5xx) | ||
throw new Error('로그인 요청 처리 중 문제가 발생했습니다.'); | ||
} else if (axiosError.request) { | ||
// 요청을 보냈지만 응답을 받지 못한 경우 | ||
throw new Error('서버 응답을 받지 못했습니다. 잠시 후 다시 시도해 주세요.'); | ||
} else { | ||
// 요청을 설정하는 과정에서 문제가 발생한 경우 | ||
throw new Error('로그인 요청을 처리하는 동안 문제가 발생했습니다.'); | ||
} | ||
} else { | ||
// Axios 에러가 아닌 경우 (네트워크 문제 등) | ||
throw new Error('알 수 없는 오류가 발생했습니다. 잠시 후 다시 시도해 주세요.'); | ||
} | ||
} | ||
const response = await httpClient.post('/auth/signIn', request); | ||
return response.data; | ||
}; | ||
|
||
export default postSignin; |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import postSignin from '@/apis/auth'; | ||
import { toast } from '@/components/ui/use-toast'; | ||
import { useMutation } from '@tanstack/react-query'; | ||
import { useRouter } from 'next/router'; | ||
|
||
const useSigninMutation = () => { | ||
const router = useRouter(); | ||
|
||
return useMutation({ | ||
mutationFn: postSignin, | ||
onSuccess: (data) => { | ||
localStorage.setItem('accessToken', data.accessToken); | ||
localStorage.setItem('refreshToken', data.refreshToken); | ||
router.push('/'); | ||
}, | ||
onError: () => { | ||
toast({ description: '이메일 혹은 비밀번호를 확인해주세요.', className: 'border-state-error text-state-error font-semibold' }); | ||
}, | ||
}); | ||
}; | ||
|
||
export default useSigninMutation; |
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 was deleted.
Oops, something went wrong.
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