forked from baron/baron-sso
devfront 세션 종료 로그아웃
This commit is contained in:
@@ -27,17 +27,23 @@ apiClient.interceptors.request.use(async (config) => {
|
|||||||
apiClient.interceptors.response.use(
|
apiClient.interceptors.response.use(
|
||||||
(response) => response,
|
(response) => response,
|
||||||
async (error) => {
|
async (error) => {
|
||||||
if (error.response?.status === 401) {
|
const status = error.response?.status;
|
||||||
// 401 발생 시 로그인 페이지로 리다이렉트
|
const message =
|
||||||
const isAuthPath = window.location.pathname.startsWith("/auth/callback");
|
error.response?.data?.error?.toString().toLowerCase() ??
|
||||||
const isLoginPath = window.location.pathname === "/login";
|
error.response?.data?.message?.toString().toLowerCase() ??
|
||||||
const user = await userManager.getUser();
|
"";
|
||||||
// 인증 토큰이 없는 경우에만 로그인으로 보낸다.
|
const isAuthPath = window.location.pathname.startsWith("/auth/callback");
|
||||||
// 토큰이 있는데 401이면 권한/백엔드 정책 이슈로 간주하고 화면에서 에러를 노출한다.
|
const isLoginPath = window.location.pathname === "/login";
|
||||||
const hasAccessToken = Boolean(user?.access_token);
|
const shouldRedirectToLogin =
|
||||||
if (!hasAccessToken && !isAuthPath && !isLoginPath) {
|
status === 401 ||
|
||||||
window.location.href = "/login";
|
(status === 403 &&
|
||||||
}
|
(message.includes("authentication required") ||
|
||||||
|
message.includes("invalid session") ||
|
||||||
|
message.includes("token is not active")));
|
||||||
|
|
||||||
|
if (shouldRedirectToLogin && !isAuthPath && !isLoginPath) {
|
||||||
|
await userManager.removeUser();
|
||||||
|
window.location.href = "/login";
|
||||||
}
|
}
|
||||||
return Promise.reject(error);
|
return Promise.reject(error);
|
||||||
},
|
},
|
||||||
|
|||||||
Reference in New Issue
Block a user