diff --git a/frontend/index.html b/frontend/index.html
index 741a47a..f954270 100644
--- a/frontend/index.html
+++ b/frontend/index.html
@@ -489,6 +489,27 @@
let currentPhotos = [];
let issues = [];
+ // 공통 헤더 초기화 함수 (중복 방지)
+ async function initializeCommonHeader(user) {
+ console.log('🔧 공통 헤더 초기화 시작:', user.username);
+
+ if (window.commonHeader && typeof window.commonHeader.init === 'function') {
+ await window.commonHeader.init(user, 'issues_create');
+ window.commonHeaderInitialized = true;
+ console.log('✅ 공통 헤더 초기화 완료');
+ } else {
+ console.error('❌ 공통 헤더 모듈이 로드되지 않음');
+ // 지연 재시도
+ setTimeout(async () => {
+ if (window.commonHeader && typeof window.commonHeader.init === 'function') {
+ console.log('🔄 지연된 공통 헤더 초기화');
+ await window.commonHeader.init(user, 'issues_create');
+ window.commonHeaderInitialized = true;
+ }
+ }, 200);
+ }
+ }
+
// 수동 초기화 함수 (initializeApp 함수가 로드되지 않을 때 사용)
async function manualInitialize() {
console.log('🔧 수동 초기화 시작');
@@ -549,6 +570,13 @@
async function initializeApp() {
console.log('🚀 앱 초기화 시작 (AuthManager 사용)');
+ // AuthManager가 이미 사용자 정보를 가지고 있다면 즉시 헤더 표시
+ if (window.authManager.isLoggedIn()) {
+ const cachedUser = window.authManager.getCurrentUser();
+ console.log('⚡ 캐시된 사용자로 즉시 헤더 초기화:', cachedUser.username);
+ await initializeCommonHeader(cachedUser);
+ }
+
try {
// AuthManager를 통한 인증 체크 (캐시 우선, 필요시에만 API 호출)
const user = await window.authManager.checkAuth();
@@ -557,20 +585,11 @@
currentUser = user;
console.log('✅ currentUser 전역 변수 업데이트:', currentUser.username);
- // 공통 헤더 초기화
- console.log('🔧 공통 헤더 초기화 시작:', user.username);
-
- if (window.commonHeader && typeof window.commonHeader.init === 'function') {
- await window.commonHeader.init(user, 'issues_create');
- console.log('✅ 공통 헤더 초기화 완료');
+ // 공통 헤더 초기화 (이미 초기화되었다면 스킵)
+ if (!window.commonHeaderInitialized) {
+ await initializeCommonHeader(user);
} else {
- console.error('❌ 공통 헤더 모듈이 로드되지 않음');
- setTimeout(() => {
- if (window.commonHeader && typeof window.commonHeader.init === 'function') {
- console.log('🔄 지연된 공통 헤더 초기화');
- window.commonHeader.init(user, 'issues_create');
- }
- }, 200);
+ console.log('✅ 공통 헤더 이미 초기화됨 - 스킵');
}
// 페이지 접근 권한 체크
@@ -605,9 +624,26 @@
}
}
- // DOM 로드 완료 시 대기 (API 스크립트가 로드되면 initializeApp 호출됨)
- window.addEventListener('DOMContentLoaded', () => {
- console.log('📄 DOM 로드 완료 - API 스크립트 로딩 대기 중...');
+ // DOM 로드 완료 시 즉시 헤더 표시 시도
+ window.addEventListener('DOMContentLoaded', async () => {
+ console.log('📄 DOM 로드 완료 - 즉시 헤더 표시 시도');
+
+ // AuthManager가 이미 로드되었고 사용자 정보가 있다면 즉시 헤더 표시
+ if (window.authManager && window.authManager.isLoggedIn()) {
+ const cachedUser = window.authManager.getCurrentUser();
+ console.log('⚡ DOM 로드 시점에서 즉시 헤더 표시:', cachedUser.username);
+
+ // 공통 헤더 모듈이 로드될 때까지 잠시 대기
+ let attempts = 0;
+ while (!window.commonHeader && attempts < 10) {
+ await new Promise(resolve => setTimeout(resolve, 50));
+ attempts++;
+ }
+
+ if (window.commonHeader) {
+ await initializeCommonHeader(cachedUser);
+ }
+ }
});
// 로그인 (AuthManager 사용)
@@ -624,9 +660,7 @@
console.log('✅ 로그인 성공 - 메인 화면 초기화');
// 공통 헤더 초기화
- if (window.commonHeader && typeof window.commonHeader.init === 'function') {
- await window.commonHeader.init(currentUser, 'issues_create');
- }
+ await initializeCommonHeader(currentUser);
// 로그인 성공 후 메인 화면 표시
document.getElementById('loginScreen').classList.add('hidden');