TK-FB(공장관리+신고)와 M-Project(부적합관리)를 3개 독립 시스템으로 분리하기 위한 전체 코드 구조 작성. - SSO 인증 서비스 (bcrypt + pbkdf2 이중 해시 지원) - System 1: 공장관리 (TK-FB 기반, 신고 코드 제거) - System 2: 신고 (TK-FB에서 workIssue 코드 추출) - System 3: 부적합관리 (M-Project 기반) - Gateway 포털 (path-based 라우팅) - 통합 docker-compose.yml 및 배포 스크립트 Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
77 lines
1.8 KiB
JavaScript
77 lines
1.8 KiB
JavaScript
/**
|
|
* 공유 네비게이션 헤더
|
|
*
|
|
* 각 시스템 페이지에서 import하여 통합 포털 네비게이션을 제공
|
|
* <script src="/shared/nav-header.js"></script>
|
|
*/
|
|
(function() {
|
|
const TOKEN_KEY = 'sso_token';
|
|
const USER_KEY = 'sso_user';
|
|
|
|
/**
|
|
* SSO 토큰 가져오기
|
|
*/
|
|
window.SSOAuth = {
|
|
getToken: function() {
|
|
return localStorage.getItem(TOKEN_KEY);
|
|
},
|
|
|
|
getUser: function() {
|
|
try {
|
|
return JSON.parse(localStorage.getItem(USER_KEY));
|
|
} catch {
|
|
return null;
|
|
}
|
|
},
|
|
|
|
isLoggedIn: function() {
|
|
return !!this.getToken();
|
|
},
|
|
|
|
logout: function() {
|
|
localStorage.removeItem(TOKEN_KEY);
|
|
localStorage.removeItem(USER_KEY);
|
|
localStorage.removeItem('sso_refresh_token');
|
|
window.location.href = '/login';
|
|
},
|
|
|
|
/**
|
|
* 토큰을 Authorization 헤더에 포함한 fetch wrapper
|
|
*/
|
|
fetch: function(url, options) {
|
|
options = options || {};
|
|
options.headers = options.headers || {};
|
|
const token = this.getToken();
|
|
if (token) {
|
|
options.headers['Authorization'] = 'Bearer ' + token;
|
|
}
|
|
return fetch(url, options);
|
|
},
|
|
|
|
/**
|
|
* 토큰 유효성 확인 (SSO 서비스 호출)
|
|
*/
|
|
validate: async function() {
|
|
const token = this.getToken();
|
|
if (!token) return false;
|
|
try {
|
|
const res = await fetch('/auth/validate', {
|
|
headers: { 'Authorization': 'Bearer ' + token }
|
|
});
|
|
return res.ok;
|
|
} catch {
|
|
return false;
|
|
}
|
|
},
|
|
|
|
/**
|
|
* 로그인 안 되어있으면 로그인 페이지로 리다이렉트
|
|
*/
|
|
requireLogin: function() {
|
|
if (!this.isLoggedIn()) {
|
|
window.location.href = '/login?redirect=' + encodeURIComponent(window.location.pathname);
|
|
}
|
|
}
|
|
};
|
|
})();
|