fix: 로그아웃 후 자동 재로그인 버그 수정

쿠키를 단일 진실 출처로 만들어 서브도메인 간 로그아웃 불일치 해결:
- login.html: logout=1 파라미터 시 localStorage+쿠키 전부 정리 후 토큰 체크 스킵
- 각 시스템 logout 함수에 &logout=1 추가 (6개 파일)
- 각 시스템 initAuth에 쿠키 우선 검증 추가 (7개 파일)

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
Hyungi Ahn
2026-03-13 09:00:19 +09:00
parent 3d6cedf667
commit 1006e8479e
10 changed files with 100 additions and 8 deletions

View File

@@ -154,7 +154,7 @@ if ('caches' in window) {
// 401 Unauthorized 처리
if (response.status === 401) {
window.clearSSOAuth();
window.location.href = window.getLoginUrl();
window.location.href = window.getLoginUrl() + '&logout=1';
throw new Error('인증이 만료되었습니다.');
}

View File

@@ -120,8 +120,24 @@ async function checkPageAccess(pageKey) {
}
}
// 쿠키 직접 읽기 (api-base.js의 cookieGet은 IIFE 내부 함수이므로 접근 불가)
function _authCookieGet(name) {
var match = document.cookie.match(new RegExp('(?:^|; )' + name + '=([^;]*)'));
return match ? decodeURIComponent(match[1]) : null;
}
// 즉시 실행 함수로 스코프를 보호하고 로직을 실행
(async function() {
// 쿠키 우선 검증: 쿠키 없고 localStorage에만 토큰이 있으면 정리
var cookieToken = _authCookieGet('sso_token');
var localToken = localStorage.getItem('sso_token');
if (!cookieToken && localToken) {
['sso_token','sso_user','sso_refresh_token','token','user','access_token',
'currentUser','current_user','userInfo','userPageAccess'].forEach(function(k) { localStorage.removeItem(k); });
window.location.href = window.getLoginUrl ? window.getLoginUrl() : '/login';
return;
}
if (!isLoggedIn()) {
clearAuthData(); // 만약을 위해 한번 더 정리
window.location.href = window.getLoginUrl ? window.getLoginUrl() : '/login';