85 lines
2.9 KiB
JavaScript
85 lines
2.9 KiB
JavaScript
async function debugLoadingIssue() {
|
|
console.log('🔍 調試管理員後台載入問題...\n');
|
|
|
|
try {
|
|
// 1. 檢查管理員頁面載入
|
|
console.log('1. 檢查管理員頁面載入...');
|
|
const response = await fetch('http://localhost:3000/admin');
|
|
|
|
if (response.ok) {
|
|
const pageContent = await response.text();
|
|
console.log('✅ 管理員頁面載入成功');
|
|
console.log('狀態碼:', response.status);
|
|
|
|
// 檢查頁面內容
|
|
if (pageContent.includes('載入中...')) {
|
|
console.log('❌ 頁面一直顯示載入中狀態');
|
|
|
|
// 檢查是否有調試信息
|
|
if (pageContent.includes('調試信息')) {
|
|
console.log('📋 發現調試信息');
|
|
const debugMatch = pageContent.match(/調試信息: 用戶=([^,]+), 角色=([^<]+)/);
|
|
if (debugMatch) {
|
|
console.log('調試信息:', {
|
|
用戶: debugMatch[1],
|
|
角色: debugMatch[2]
|
|
});
|
|
}
|
|
} else {
|
|
console.log('⚠️ 沒有調試信息,可能是載入狀態問題');
|
|
}
|
|
|
|
// 檢查頁面是否包含管理員內容
|
|
if (pageContent.includes('儀表板') || pageContent.includes('管理員')) {
|
|
console.log('✅ 頁面包含管理員內容,但被載入狀態覆蓋');
|
|
} else {
|
|
console.log('❌ 頁面不包含管理員內容');
|
|
}
|
|
|
|
} else if (pageContent.includes('存取被拒')) {
|
|
console.log('❌ 頁面顯示存取被拒');
|
|
} else if (pageContent.includes('儀表板') || pageContent.includes('管理員')) {
|
|
console.log('✅ 管理員頁面正常顯示');
|
|
} else {
|
|
console.log('⚠️ 頁面內容不確定');
|
|
}
|
|
|
|
} else {
|
|
console.log('❌ 管理員頁面載入失敗:', response.status);
|
|
}
|
|
|
|
// 2. 檢查登入狀態
|
|
console.log('\n2. 檢查登入狀態...');
|
|
const loginResponse = await fetch('http://localhost:3000/api/auth/login', {
|
|
method: 'POST',
|
|
headers: {
|
|
'Content-Type': 'application/json',
|
|
},
|
|
body: JSON.stringify({
|
|
email: 'admin@ai-platform.com',
|
|
password: 'admin123456'
|
|
})
|
|
});
|
|
|
|
if (loginResponse.ok) {
|
|
const loginData = await loginResponse.json();
|
|
console.log('✅ 管理員登入 API 正常');
|
|
console.log('用戶角色:', loginData.user?.role);
|
|
} else {
|
|
console.log('❌ 管理員登入 API 失敗:', loginResponse.status);
|
|
}
|
|
|
|
console.log('\n🎉 載入問題調試完成!');
|
|
console.log('\n💡 可能的原因:');
|
|
console.log('1. isInitialized 狀態沒有正確設置');
|
|
console.log('2. 客戶端載入邏輯有問題');
|
|
console.log('3. localStorage 中的用戶資料有問題');
|
|
console.log('4. 載入條件邏輯有問題');
|
|
|
|
} catch (error) {
|
|
console.error('❌ 調試過程中發生錯誤:', error);
|
|
}
|
|
}
|
|
|
|
debugLoadingIssue();
|