Skip to content

Commit ec7866e

Browse files
committed
Merge branch 'trae' of https://github.com/YuJunZhiXue/qwen2API into trae
2 parents fb87c27 + e2ae9df commit ec7866e

1 file changed

Lines changed: 19 additions & 3 deletions

File tree

frontend/src/lib/auth.ts

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,20 @@
1-
export function getAuthHeader() {
2-
const key = localStorage.getItem('qwen2api_key') || 'admin';
3-
return { Authorization: `Bearer ${key}` };
1+
/**
2+
* 读取当前会话凭证。
3+
* - 优先使用 localStorage 中用户显式保存的 key
4+
* - 仅在没有任何配置时回退到 "admin",避免页面切换/刷新后静默丢失凭证
5+
*/
6+
export function getStoredApiKey(): string {
7+
try {
8+
const stored = localStorage.getItem('qwen2api_key')
9+
if (stored && stored.trim()) return stored.trim()
10+
} catch {
11+
// localStorage 不可用时继续走默认值
12+
}
13+
return 'admin'
14+
}
15+
16+
export function getAuthHeader(): Record<string, string> {
17+
const key = getStoredApiKey()
18+
if (!key) return {}
19+
return { Authorization: `Bearer ${key}` }
420
}

0 commit comments

Comments
 (0)