- 更新admin/dashboard页面:完善API集成,删除假数据 - 更新admin/login和channel/login:优化登录流程 - 更新agent-factory、billing、data-tools、model-gateway、orchestration页面:API集成优化 - 更新channel/dashboard:渠道管理功能完善 - 更新lib/api-client.ts:API客户端功能增强 - 更新lib/auth.ts:认证功能优化 - 删除过时的API文档文件
61 lines
1.4 KiB
TypeScript
61 lines
1.4 KiB
TypeScript
// Authentication utilities
|
|
|
|
export function getAuthToken(): string | null {
|
|
if (typeof window !== "undefined") {
|
|
// 检查所有可能的token类型
|
|
const authToken = localStorage.getItem("auth_token")
|
|
const adminToken = localStorage.getItem("admin_token")
|
|
const channelToken = localStorage.getItem("channel_token")
|
|
|
|
return authToken || adminToken || channelToken
|
|
}
|
|
return null
|
|
}
|
|
|
|
export function getUser(): any | null {
|
|
if (typeof window !== "undefined") {
|
|
const userStr = localStorage.getItem("user")
|
|
if (userStr) {
|
|
try {
|
|
return JSON.parse(userStr)
|
|
} catch {
|
|
return null
|
|
}
|
|
}
|
|
}
|
|
return null
|
|
}
|
|
|
|
export function isAuthenticated(): boolean {
|
|
return getAuthToken() !== null
|
|
}
|
|
|
|
export function isAdminAuthenticated(): boolean {
|
|
if (typeof window !== "undefined") {
|
|
return localStorage.getItem("admin_token") !== null
|
|
}
|
|
return false
|
|
}
|
|
|
|
export function isChannelAuthenticated(): boolean {
|
|
if (typeof window !== "undefined") {
|
|
return localStorage.getItem("channel_token") !== null
|
|
}
|
|
return false
|
|
}
|
|
|
|
export function clearAuth(): void {
|
|
if (typeof window !== "undefined") {
|
|
localStorage.removeItem("auth_token")
|
|
localStorage.removeItem("refresh_token")
|
|
localStorage.removeItem("user")
|
|
localStorage.removeItem("api_key")
|
|
}
|
|
}
|
|
|
|
export function getRole(): string | null {
|
|
const user = getUser()
|
|
return user?.role || null
|
|
}
|
|
|