diff --git a/frontend/app/generate/page.tsx b/frontend/app/generate/page.tsx index 06438bd..361cf39 100644 --- a/frontend/app/generate/page.tsx +++ b/frontend/app/generate/page.tsx @@ -97,10 +97,14 @@ function GenerateContent() { setIsAnalyzing(true) try { + // 獲取認證 token + const token = typeof window !== 'undefined' ? localStorage.getItem('auth_token') : null + const response = await fetch(`${API_CONFIG.BASE_URL}/api/ai/analyze-sentence`, { method: 'POST', headers: { - 'Content-Type': 'application/json' + 'Content-Type': 'application/json', + ...(token && { 'Authorization': `Bearer ${token}` }) }, body: JSON.stringify({ inputText: textInput, @@ -116,6 +120,9 @@ function GenerateContent() { }) if (!response.ok) { + if (response.status === 401) { + throw new Error('請先登入後再使用 AI 分析功能') + } throw new Error(`API請求失敗: ${response.status}`) }