Skip to content

Commit 4a188b5

Browse files
committed
fix(assistant): inject authToken and userApiKey into chat IPC call — resolves 401
1 parent 59ce053 commit 4a188b5

1 file changed

Lines changed: 9 additions & 0 deletions

File tree

‎client/src/features/assistant/hooks/useChat.ts‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ import { useCallback, useEffect } from 'react';
1212
import { useAssistantStore } from '../store/useAssistantStore';
1313
import { SESSION_EXPIRE_MS, HISTORY_PAGE_SIZE, CONTEXT_WINDOW_ROUNDS } from '../constants';
1414
import type { ChatMessage } from '../types';
15+
import { supabase } from '@/lib/auth/supabaseClient';
16+
import { getActiveUserKey } from '@/lib/ai/apiKeyManager';
1517

1618
/** 错误标记——MessageBubble 据此渲染重试/关闭按钮 */
1719
export const ERROR_MARKER = '__ASSISTANT_ERROR__';
@@ -124,6 +126,11 @@ export function useChat() {
124126
});
125127

126128
try {
129+
// 鉴权:从 Supabase session 获取 token(同其他 AI 功能模式)
130+
const { data: { session } } = await supabase.auth.getSession();
131+
const authToken = session?.access_token ?? undefined;
132+
const userApiKey = getActiveUserKey();
133+
127134
// chatHandler 在整个流结束后才 return(invoke 阻塞至流完成),
128135
// 期间 chunk/end/error 事件由上方监听器处理。
129136
await api.invoke('ai:chat:send', {
@@ -132,6 +139,8 @@ export function useChat() {
132139
message: text,
133140
history,
134141
scene: 'study',
142+
authToken,
143+
userApiKey,
135144
});
136145
} catch {
137146
appendToLastMessage(ERROR_MARKER);

0 commit comments

Comments
 (0)