Skip to content

Commit 21a21b7

Browse files
SonAIengineclaude
andcommitted
fix: AI CLI 인증 토큰 전달 개선 — cookie fallback + 토큰 부재 경고
- cli.html: URL param 없으면 document.cookie에서 access_token fallback - 토큰 없을 때 UI에 경고 메시지 표시 ("로그인 후 다시 열어주세요") - tool_search: 토큰 유무 로깅 추가 (디버그용) - 토큰 전달 흐름: 사이드바 쿠키 → URL param → cli.html → invoke → Rust → graph-tool-call --auth-token Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent 5c91dc1 commit 21a21b7

2 files changed

Lines changed: 23 additions & 2 deletions

File tree

src-cli/cli.html

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -202,10 +202,24 @@
202202
let streamingText = '';
203203
let currentStreamEl = null;
204204

205-
// Get auth token from URL query param (passed by open_cli_window)
205+
// Get auth token: URL param → cookie → Tauri state
206206
function getToken() {
207+
// 1. URL query param (passed by open_cli_window)
207208
const params = new URLSearchParams(window.location.search);
208-
return params.get('token') || null;
209+
const paramToken = params.get('token');
210+
if (paramToken) {
211+
console.log('[CLI] Token from URL param:', paramToken.substring(0, 20) + '...');
212+
return paramToken;
213+
}
214+
// 2. Cookie fallback (same origin in Tauri webview)
215+
const match = document.cookie.match(/(^| )access_token=([^;]+)/);
216+
const cookieToken = match ? decodeURIComponent(match[2]) : null;
217+
if (cookieToken) {
218+
console.log('[CLI] Token from cookie:', cookieToken.substring(0, 20) + '...');
219+
return cookieToken;
220+
}
221+
console.warn('[CLI] No auth token found!');
222+
return null;
209223
}
210224

211225
// Load providers
@@ -365,6 +379,10 @@
365379
});
366380

367381
// Initialize
382+
const initToken = getToken();
383+
if (!initToken) {
384+
addMessage('system', '⚠️ 인증 토큰이 없습니다. 로그인 후 AI CLI를 다시 열어주세요.');
385+
}
368386
loadProviders();
369387
</script>
370388
</body>

src-tauri/src/services/tool_search.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -280,7 +280,10 @@ pub async fn execute_tool_call(
280280
]);
281281

282282
if let Some(token) = auth_token {
283+
log::info!("execute_tool_call: auth token present ({}...)", &token[..token.len().min(20)]);
283284
cmd.args(["--auth-token", token]);
285+
} else {
286+
log::warn!("execute_tool_call: NO auth token — API calls requiring auth will fail");
284287
}
285288

286289
if !args_str.is_empty() && args_str != "{}" && args_str != "null" {

0 commit comments

Comments
 (0)