Skip to content

Commit 79fcf18

Browse files
committed
♻️ refactor:로그인 실패시 리다이렉트 방지
Issue Resolved: #
1 parent f812a06 commit 79fcf18

File tree

1 file changed

+11
-7
lines changed

1 file changed

+11
-7
lines changed

front/src/api/axios.ts

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -23,21 +23,27 @@ export const apiClient = axios.create({
2323
withCredentials: true,
2424
});
2525

26-
const EXCLUDING_AUTH_ERROR_REDIRECT_URL_LIST = ['/user'];
2726
const UN_AUTHENTICATION_ERROR_STATUS = 403;
27+
const EXCLUDE_AUTHENTICATION_ERROR_API_URL_LIST = ['/user'];
2828
const UN_AUTHORIZATION_ERROR_STATUS = 401;
29+
const EXCLUDE_AUTHORIZATION_ERROR_API_URL_LIST = ['/user/login'];
30+
2931
const isAuthenticateError = (error: AxiosError) => {
3032
if (
3133
error.status === UN_AUTHENTICATION_ERROR_STATUS &&
3234
error.config?.url &&
33-
!EXCLUDING_AUTH_ERROR_REDIRECT_URL_LIST.includes(error.config.url)
35+
!EXCLUDE_AUTHENTICATION_ERROR_API_URL_LIST.includes(error.config.url)
3436
)
3537
return true;
3638
return false;
3739
};
3840

3941
const isAuthorizationError = (error: AxiosError) => {
40-
if (error.status === UN_AUTHORIZATION_ERROR_STATUS) {
42+
if (
43+
error.status === UN_AUTHORIZATION_ERROR_STATUS &&
44+
error.config?.url &&
45+
!EXCLUDE_AUTHORIZATION_ERROR_API_URL_LIST.includes(error.config.url)
46+
) {
4147
return true;
4248
}
4349
return false;
@@ -61,12 +67,10 @@ apiClient.interceptors.response.use(
6167
toast.error('로그인이 필요합니다.\n로그인 후 이용해주세요.');
6268
auth.logout();
6369
router.navigate(ROUTE_URL.USER.LOGIN, { replace: true });
64-
}
65-
if (isAuthorizationError(error)) {
70+
} else if (isAuthorizationError(error)) {
6671
toast.error('잘못된 접근입니다.\n다시 시도해주세요.');
6772
router.navigate('/', { replace: true });
68-
}
69-
if (isServerError(error)) {
73+
} else if (isServerError(error)) {
7074
toast.error('서버에 문제가 있습니다.\n잠시 후 다시 시도해주세요.');
7175
}
7276
throw error;

0 commit comments

Comments
 (0)