Skip to content

Commit 32921eb

Browse files
committed
feat: 로그아웃 에러 처리 로직 개선
1 parent af8cd40 commit 32921eb

3 files changed

Lines changed: 41 additions & 15 deletions

File tree

apps/ticket/src/app/(pages)/mypage/_clientBoundary/UserProfileClient/index.tsx

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import { usePatchUserInfoMutation } from "@/data/users/patchUserInfo/mutation";
99
import { useUserEmailCheckMutation } from "@/data/users/postUserEmailCheck/mutation";
1010
import { useLogoutMutation } from "@/data/users/postUserLogout/mutation";
1111
import { USER_QUERY_KEYS } from "@/data/users/queryKeys";
12+
import { ERROR_CODE } from "@/lib/axios/utils/errorCode";
1213
import { safeLocalStorage } from "@/lib/storage";
1314
import { IS_LOGINED } from "@/shared/constants/storage";
1415
import { isAxiosErrorResponse } from "@/shared/types/axioxError";
@@ -147,6 +148,10 @@ export const UserProfileClient = () => {
147148
window.location.href = "/login";
148149
} catch (error) {
149150
if (isAxiosErrorResponse(error)) {
151+
if (error.code === ERROR_CODE.NO_ACCESS_TOKEN) {
152+
return;
153+
}
154+
150155
alert(error.message);
151156
}
152157
}

apps/ticket/src/lib/axios/index.ts

Lines changed: 21 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ instance.interceptors.request.use(
2828
);
2929

3030
let isAlertShown = false;
31+
let isLoginAlertShown = false;
3132

3233
// 응답 인터셉터
3334
instance.interceptors.response.use(
@@ -52,29 +53,30 @@ instance.interceptors.response.use(
5253
if (isAxiosErrorResponse(error.response?.data)) {
5354
// 엑세스 토큰 없음
5455
if (error.response?.data.code === ERROR_CODE.NO_ACCESS_TOKEN) {
55-
alert("로그인이 필요한 페이지입니다.");
56+
if (error.config?.url === API_URL.USER.LOGOUT) {
57+
safeLocalStorage.remove(IS_LOGINED);
58+
59+
return;
60+
}
5661

57-
safeLocalStorage.remove(IS_LOGINED);
58-
window.location.href = "/login";
62+
redirectToLoginOnce();
5963

6064
return;
6165
}
6266

6367
if (error.response?.data.code === ERROR_CODE.LOGIN_REQUIRED) {
6468
// 인증 페이지에서는 로그인 페이지로 이동하지 않음
6569
if (window.location.pathname !== "/auth") {
66-
alert("로그인이 필요한 페이지입니다.");
70+
redirectToLoginOnce();
6771

68-
safeLocalStorage.remove(IS_LOGINED);
69-
window.location.href = "/login";
72+
return;
7073
}
7174
}
7275

7376
if (error.response?.data.code === ERROR_CODE.REFRESH_TOKEN_EXPIRED) {
74-
alert("로그인이 필요한 페이지입니다.");
77+
redirectToLoginOnce();
7578

76-
safeLocalStorage.remove(IS_LOGINED);
77-
window.location.href = "/login";
79+
return;
7880
}
7981
}
8082

@@ -121,3 +123,13 @@ instance.interceptors.response.use(
121123
return Promise.reject(error.response?.data);
122124
},
123125
);
126+
127+
function redirectToLoginOnce() {
128+
if (isLoginAlertShown) return;
129+
130+
isLoginAlertShown = true;
131+
132+
alert("로그인이 필요한 페이지입니다.");
133+
safeLocalStorage.remove(IS_LOGINED);
134+
window.location.href = "/login";
135+
}

apps/ticket/src/shared/components/Footer/index.tsx

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,21 @@ export const Footer = () => {
2727
<Typography type="body12" color="gray400">
2828
Copyright © 2024 PERMIT
2929
</Typography>
30-
<Typography type="body12" color="gray400">
31-
Instagram_Permit
32-
</Typography>
33-
<Typography type="body12" color="gray400">
34-
Instagram_ceiling
35-
</Typography>
30+
<a href="https://www.instagram.com/permit_invites/" target="_blank" rel="noreferrer">
31+
<Typography type="body12" color="gray400">
32+
Instagram_Permit
33+
</Typography>
34+
</a>
35+
<a href="https://www.instagram.com/ceilingservice/" target="_blank" rel="noreferrer">
36+
<Typography type="body12" color="gray400">
37+
Instagram_Ceiling
38+
</Typography>
39+
</a>
40+
<a href="https://www.instagram.com/olympan.kr/" target="_blank" rel="noreferrer">
41+
<Typography type="body12" color="gray400">
42+
Instagram_Olympan
43+
</Typography>
44+
</a>
3645
<Typography type="body12" color="gray400">
3746
hello@permitseoul.com
3847
</Typography>

0 commit comments

Comments
 (0)