@@ -28,6 +28,7 @@ instance.interceptors.request.use(
2828) ;
2929
3030let isAlertShown = false ;
31+ let isLoginAlertShown = false ;
3132
3233// 응답 인터셉터
3334instance . 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+ }
0 commit comments