fix: tkfb 로그인을 SSO 인증으로 변경
system1-factory의 자체 로그인 폼을 제거하고 게이트웨이 SSO 로그인 페이지(/login)로 리다이렉트하도록 변경. 기존에는 /api/auth/login(system1-api)으로 직접 인증하여 SSO 사용자가 401 오류를 받았음. - index.html: 로그인 폼 제거, SSO 토큰 없으면 /login으로 리다이렉트 - api-base.js: getLoginUrl() 개발환경에서도 SSO 로그인 경로 반환 - api-helper.js: authFetch 401/토큰없음 시 SSO 로그인으로 리다이렉트 - app-init.js: 로그아웃 및 인증실패 시 SSO 로그인으로 리다이렉트 Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -6,13 +6,18 @@ const API_BASE_URL = window.API_BASE_URL || 'http://localhost:30005/api';
|
||||
|
||||
// 인증 관련 함수들 (직접 구현)
|
||||
function getToken() {
|
||||
const token = localStorage.getItem('sso_token');
|
||||
// SSO 토큰 우선, 기존 token 폴백
|
||||
if (window.getSSOToken) return window.getSSOToken();
|
||||
const token = localStorage.getItem('sso_token') || localStorage.getItem('token');
|
||||
return token && token !== 'undefined' && token !== 'null' ? token : null;
|
||||
}
|
||||
|
||||
function clearAuthData() {
|
||||
if (window.clearSSOAuth) { window.clearSSOAuth(); return; }
|
||||
localStorage.removeItem('sso_token');
|
||||
localStorage.removeItem('sso_user');
|
||||
localStorage.removeItem('token');
|
||||
localStorage.removeItem('user');
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -45,11 +50,11 @@ async function login(username, password) {
|
||||
*/
|
||||
async function authFetch(endpoint, options = {}) {
|
||||
const token = getToken();
|
||||
|
||||
|
||||
if (!token) {
|
||||
console.error('토큰이 없습니다. 로그인이 필요합니다.');
|
||||
clearAuthData(); // 인증 정보 정리
|
||||
window.location.href = '/login'; // 로그인 페이지로 리디렉션
|
||||
window.location.href = window.getLoginUrl ? window.getLoginUrl() : '/login?redirect=' + encodeURIComponent(window.location.href);
|
||||
// 에러를 던져서 후속 실행을 중단
|
||||
throw new Error('인증 토큰이 없습니다.');
|
||||
}
|
||||
@@ -71,7 +76,7 @@ async function authFetch(endpoint, options = {}) {
|
||||
if (response.status === 401) {
|
||||
console.error('인증 실패. 토큰이 만료되었거나 유효하지 않습니다.');
|
||||
clearAuthData(); // 만료된 인증 정보 정리
|
||||
window.location.href = '/login';
|
||||
window.location.href = window.getLoginUrl ? window.getLoginUrl() : '/login?redirect=' + encodeURIComponent(window.location.href);
|
||||
throw new Error('인증에 실패했습니다.');
|
||||
}
|
||||
|
||||
@@ -133,4 +138,4 @@ window.apiPost = apiPost;
|
||||
window.apiPut = apiPut;
|
||||
window.apiDelete = apiDelete;
|
||||
window.getToken = getToken;
|
||||
window.clearAuthData = clearAuthData;
|
||||
window.clearAuthData = clearAuthData;
|
||||
|
||||
Reference in New Issue
Block a user