forked from baron/baron-sso
로그인 콜백-가드 흐름 및 API 인증 처리 안정화
This commit is contained in:
@@ -26,12 +26,16 @@ apiClient.interceptors.request.use(async (config) => {
|
||||
|
||||
apiClient.interceptors.response.use(
|
||||
(response) => response,
|
||||
(error) => {
|
||||
async (error) => {
|
||||
if (error.response?.status === 401) {
|
||||
// 401 발생 시 로그인 페이지로 리다이렉트
|
||||
const isAuthPath = window.location.pathname.startsWith("/callback");
|
||||
const isAuthPath = window.location.pathname.startsWith("/auth/callback");
|
||||
const isLoginPath = window.location.pathname === "/login";
|
||||
if (!isAuthPath && !isLoginPath) {
|
||||
const user = await userManager.getUser();
|
||||
// 인증 토큰이 없는 경우에만 로그인으로 보낸다.
|
||||
// 토큰이 있는데 401이면 권한/백엔드 정책 이슈로 간주하고 화면에서 에러를 노출한다.
|
||||
const hasAccessToken = Boolean(user?.access_token);
|
||||
if (!hasAccessToken && !isAuthPath && !isLoginPath) {
|
||||
window.location.href = "/login";
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user