fix: 페이지 이동 시 자동 로그아웃 및 헤더 안보임 문제 해결
🔍 Root Cause Analysis: 1. initializeApp 함수 정의 전에 호출되는 스크립트 로딩 순서 문제 2. 공통 헤더 모듈 로드 타이밍 이슈 3. currentUser undefined로 인한 연쇄 오류 🔧 Key Fixes: - initializeApp 함수 존재 여부 확인 후 호출 - 함수 미정의 시 100ms 지연 후 재시도 - manualInitialize 대안 함수 추가 (완전한 fallback) - 공통 헤더 모듈 로드 상태 확인 및 지연 초기화 - 상세한 디버깅 로그로 각 단계 추적 🛡️ Enhanced Error Handling: - 스크립트 로딩 실패 시 대안 경로 제공 - 공통 헤더 초기화 실패 시 지연 재시도 - 각 모듈별 로드 상태 확인 로직 🎯 Expected Results: - 페이지 간 이동 시 안정적인 사용자 세션 유지 - 공통 헤더 일관된 표시 - currentUser 정상 초기화 - 자동 로그아웃 문제 해결 🔍 Debug Logs Added: - 🚀 initializeApp 함수 호출 시작 - 🔧 수동 초기화 시작 - ✅/❌ 각 모듈 로드 성공/실패 상태 - 🔄 지연된 초기화 시도
This commit is contained in:
@@ -446,8 +446,24 @@
|
||||
console.log('🔍 API_BASE_URL:', typeof API_BASE_URL !== 'undefined' ? API_BASE_URL : 'undefined');
|
||||
console.log('🌐 현재 hostname:', window.location.hostname);
|
||||
console.log('🔗 현재 protocol:', window.location.protocol);
|
||||
// API 로드 후 초기화 시작
|
||||
initializeApp();
|
||||
|
||||
// initializeApp 함수가 정의되었는지 확인
|
||||
if (typeof initializeApp === 'function') {
|
||||
console.log('🚀 initializeApp 함수 호출 시작');
|
||||
initializeApp();
|
||||
} else {
|
||||
console.error('❌ initializeApp 함수가 정의되지 않음');
|
||||
// 대안: 직접 초기화 로직 실행
|
||||
setTimeout(() => {
|
||||
if (typeof initializeApp === 'function') {
|
||||
console.log('🔄 지연된 initializeApp 함수 호출');
|
||||
initializeApp();
|
||||
} else {
|
||||
console.error('❌ initializeApp 함수를 찾을 수 없음 - 수동 초기화');
|
||||
manualInitialize();
|
||||
}
|
||||
}, 100);
|
||||
}
|
||||
};
|
||||
script.setAttribute('cache-control', 'no-cache, no-store, must-revalidate');
|
||||
script.setAttribute('pragma', 'no-cache');
|
||||
@@ -472,6 +488,62 @@
|
||||
let currentPhotos = [];
|
||||
let issues = [];
|
||||
|
||||
// 수동 초기화 함수 (initializeApp 함수가 로드되지 않을 때 사용)
|
||||
async function manualInitialize() {
|
||||
console.log('🔧 수동 초기화 시작');
|
||||
|
||||
// 토큰이 있으면 사용자 정보 가져오기
|
||||
const token = localStorage.getItem('access_token');
|
||||
if (token) {
|
||||
try {
|
||||
// 토큰으로 사용자 정보 가져오기 (API 호출)
|
||||
const user = await AuthAPI.getCurrentUser();
|
||||
currentUser = user;
|
||||
|
||||
// localStorage에도 백업 저장
|
||||
localStorage.setItem('currentUser', JSON.stringify(user));
|
||||
|
||||
// 공통 헤더 초기화
|
||||
console.log('🔧 수동 초기화 - 공통 헤더 초기화 시작:', user);
|
||||
console.log('window.commonHeader 존재:', !!window.commonHeader);
|
||||
|
||||
if (window.commonHeader && typeof window.commonHeader.init === 'function') {
|
||||
await window.commonHeader.init(user, 'issues_create');
|
||||
console.log('✅ 수동 초기화 - 공통 헤더 초기화 완료');
|
||||
} else {
|
||||
console.error('❌ 수동 초기화 - 공통 헤더 모듈이 로드되지 않음');
|
||||
}
|
||||
|
||||
// 페이지 접근 권한 체크 (부적합 등록 페이지)
|
||||
setTimeout(() => {
|
||||
if (typeof canAccessPage === 'function' && !canAccessPage('issues_create')) {
|
||||
alert('부적합 등록 페이지에 접근할 권한이 없습니다.');
|
||||
window.location.href = '/issue-view.html';
|
||||
return;
|
||||
}
|
||||
}, 500);
|
||||
|
||||
// 사용자 정보는 공통 헤더에서 표시됨
|
||||
document.getElementById('loginScreen').classList.add('hidden');
|
||||
document.getElementById('mainScreen').classList.remove('hidden');
|
||||
|
||||
// 프로젝트 로드
|
||||
await loadProjects();
|
||||
|
||||
loadIssues();
|
||||
|
||||
// URL 해시 처리
|
||||
handleUrlHash();
|
||||
|
||||
} catch (error) {
|
||||
console.error('수동 초기화 실패:', error);
|
||||
// 토큰이 유효하지 않으면 로그아웃
|
||||
localStorage.removeItem('access_token');
|
||||
localStorage.removeItem('currentUser');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// API 로드 후 앱 초기화
|
||||
async function initializeApp() {
|
||||
console.log('🚀 앱 초기화 시작');
|
||||
@@ -489,8 +561,21 @@
|
||||
|
||||
// 공통 헤더 초기화
|
||||
console.log('🔧 공통 헤더 초기화 시작:', user);
|
||||
await window.commonHeader.init(user, 'issues_create');
|
||||
console.log('✅ 공통 헤더 초기화 완료');
|
||||
console.log('window.commonHeader 존재:', !!window.commonHeader);
|
||||
|
||||
if (window.commonHeader && typeof window.commonHeader.init === 'function') {
|
||||
await window.commonHeader.init(user, 'issues_create');
|
||||
console.log('✅ 공통 헤더 초기화 완료');
|
||||
} else {
|
||||
console.error('❌ 공통 헤더 모듈이 로드되지 않음');
|
||||
// 대안: 기본 사용자 정보 표시
|
||||
setTimeout(() => {
|
||||
if (window.commonHeader && typeof window.commonHeader.init === 'function') {
|
||||
console.log('🔄 지연된 공통 헤더 초기화');
|
||||
window.commonHeader.init(user, 'issues_create');
|
||||
}
|
||||
}, 200);
|
||||
}
|
||||
|
||||
// 페이지 접근 권한 체크 (부적합 등록 페이지)
|
||||
setTimeout(() => {
|
||||
|
||||
Reference in New Issue
Block a user