// /js/app-init.js // System 2 (신고 시스템) 앱 초기화 - SSO 인증 체크 (function() { 'use strict'; // ===== 인증 함수 (api-base.js의 전역 헬퍼 활용) ===== function isLoggedIn() { var token = window.getSSOToken ? window.getSSOToken() : localStorage.getItem('sso_token'); return token && token !== 'undefined' && token !== 'null'; } function getUser() { return window.getSSOUser ? window.getSSOUser() : (function() { var u = localStorage.getItem('sso_user'); return u ? JSON.parse(u) : null; })(); } function clearAuthData() { if (window.clearSSOAuth) { window.clearSSOAuth(); return; } localStorage.removeItem('sso_token'); localStorage.removeItem('sso_user'); } // ===== 메인 초기화 ===== async function init() { // 1. 인증 확인 if (!isLoggedIn()) { clearAuthData(); window.location.href = window.getLoginUrl ? window.getLoginUrl() : '/login'; return; } var currentUser = getUser(); if (!currentUser || !currentUser.username) { clearAuthData(); window.location.href = window.getLoginUrl ? window.getLoginUrl() : '/login'; return; } console.log('[System2] 인증 확인:', currentUser.username); } // DOMContentLoaded 시 실행 if (document.readyState === 'loading') { document.addEventListener('DOMContentLoaded', init); } else { init(); } // 전역 노출 window.appInit = { getUser: getUser, clearAuthData: clearAuthData, isLoggedIn: isLoggedIn }; })();