fix: 수신함 로그인 튕김 문제 해결 - 강화된 디버깅 및 에러 처리
🔧 Root Cause Analysis: - 수신함 페이지에서 3가지 경우에 로그인 화면으로 리다이렉트: 1. 토큰 없음 (정상) 2. 페이지 접근 권한 없음 (과도한 체크) 3. API 호출 실패 (과도한 에러 처리) 🎯 Key Fixes: - updateStatistics() → loadStatistics() 함수명 불일치 해결 - 과도한 에러 처리 개선: 401 에러만 로그아웃, 나머지는 경고 후 계속 - 권한 체크 로직에 상세 디버깅 로그 추가 - 초기화 과정 전체에 단계별 로그 추가 🔍 Enhanced Debugging: - 🚀 수신함 초기화 시작 - 📡 사용자 정보 API 호출 시작 - 🔐 수신함 페이지 접근 권한 체크 시작 - ✅/❌ 각 단계별 성공/실패 로그 - ⚠️ 비정상 상황 감지 및 대응 🛡️ Improved Error Handling: - 401/Unauthorized 에러: 로그아웃 처리 (기존) - 기타 에러: 사용자 알림 + 빈 상태로 계속 진행 (신규) - 공통 헤더 fallback 초기화 (localStorage 기반) - 권한 함수 미로드 시 스킵 처리 🎯 Expected Result: - 실제 인증 문제만 로그인 화면으로 이동 - 네트워크/데이터 로드 실패는 경고 후 계속 사용 가능 - 상세한 로그로 정확한 원인 파악 가능 - 사용자 경험 대폭 개선
This commit is contained in:
@@ -386,14 +386,21 @@
|
||||
|
||||
// API 로드 후 초기화 함수
|
||||
async function initializeInbox() {
|
||||
console.log('🚀 수신함 초기화 시작');
|
||||
|
||||
const token = localStorage.getItem('access_token');
|
||||
console.log('토큰 존재:', !!token);
|
||||
|
||||
if (!token) {
|
||||
console.log('❌ 토큰 없음 - 로그인 페이지로 이동');
|
||||
window.location.href = '/index.html';
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
console.log('📡 사용자 정보 API 호출 시작');
|
||||
const user = await AuthAPI.getCurrentUser();
|
||||
console.log('✅ 사용자 정보 로드 성공:', user);
|
||||
currentUser = user;
|
||||
localStorage.setItem('currentUser', JSON.stringify(user));
|
||||
|
||||
@@ -402,23 +409,56 @@
|
||||
|
||||
// 페이지 접근 권한 체크
|
||||
setTimeout(() => {
|
||||
if (!canAccessPage('issues_inbox')) {
|
||||
alert('수신함 페이지에 접근할 권한이 없습니다.');
|
||||
window.location.href = '/index.html';
|
||||
return;
|
||||
console.log('🔐 수신함 페이지 접근 권한 체크 시작');
|
||||
console.log('현재 사용자:', currentUser);
|
||||
console.log('canAccessPage 함수 존재:', typeof canAccessPage);
|
||||
|
||||
if (typeof canAccessPage === 'function') {
|
||||
const hasAccess = canAccessPage('issues_inbox');
|
||||
console.log('수신함 접근 권한:', hasAccess);
|
||||
|
||||
if (!hasAccess) {
|
||||
console.log('❌ 수신함 접근 권한 없음 - 메인 페이지로 이동');
|
||||
alert('수신함 페이지에 접근할 권한이 없습니다.');
|
||||
window.location.href = '/index.html';
|
||||
return;
|
||||
} else {
|
||||
console.log('✅ 수신함 접근 권한 확인됨');
|
||||
}
|
||||
} else {
|
||||
console.log('⚠️ canAccessPage 함수가 로드되지 않음 - 권한 체크 스킵');
|
||||
}
|
||||
}, 500);
|
||||
|
||||
// 데이터 로드
|
||||
await loadProjects();
|
||||
await loadIssues();
|
||||
updateStatistics();
|
||||
// loadIssues()에서 이미 loadStatistics() 호출함
|
||||
|
||||
} catch (error) {
|
||||
console.error('인증 실패:', error);
|
||||
localStorage.removeItem('access_token');
|
||||
localStorage.removeItem('currentUser');
|
||||
window.location.href = '/index.html';
|
||||
console.error('수신함 초기화 실패:', error);
|
||||
|
||||
// 401 Unauthorized 에러인 경우만 로그아웃 처리
|
||||
if (error.message && (error.message.includes('401') || error.message.includes('Unauthorized') || error.message.includes('Not authenticated'))) {
|
||||
console.log('🔐 인증 토큰 만료 - 로그아웃 처리');
|
||||
localStorage.removeItem('access_token');
|
||||
localStorage.removeItem('currentUser');
|
||||
window.location.href = '/index.html';
|
||||
} else {
|
||||
// 다른 에러는 사용자에게 알리고 계속 진행
|
||||
console.log('⚠️ 데이터 로드 실패 - 빈 상태로 표시');
|
||||
alert('일부 데이터를 불러오는데 실패했습니다. 새로고침 후 다시 시도해주세요.');
|
||||
|
||||
// 공통 헤더만이라도 초기화
|
||||
try {
|
||||
const user = JSON.parse(localStorage.getItem('currentUser') || '{}');
|
||||
if (user.id) {
|
||||
await window.commonHeader.init(user, 'issues_inbox');
|
||||
}
|
||||
} catch (headerError) {
|
||||
console.error('공통 헤더 초기화 실패:', headerError);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user