Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 19 additions & 3 deletions frontend/src/lib/auth.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,20 @@
export function getAuthHeader() {
const key = localStorage.getItem('qwen2api_key') || 'admin';
return { Authorization: `Bearer ${key}` };
/**
* 读取当前会话凭证。
* - 优先使用 localStorage 中用户显式保存的 key
* - 仅在没有任何配置时回退到 "admin",避免页面切换/刷新后静默丢失凭证
*/
export function getStoredApiKey(): string {
try {
const stored = localStorage.getItem('qwen2api_key')
if (stored && stored.trim()) return stored.trim()
} catch {
// localStorage 不可用时继续走默认值
}
return 'admin'
}

export function getAuthHeader(): Record<string, string> {
const key = getStoredApiKey()
if (!key) return {}
return { Authorization: `Bearer ${key}` }
}
Loading