ai-chat-ui/src/services/authService.ts

64 lines
1.3 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

/**
* 认证服务模块 - 预留接口
*
* 当前返回默认用户,未来可集成 JWT、OAuth 等认证系统
*/
export interface AuthUser {
id: string;
name?: string;
email?: string;
}
// Token 存储 key
const AUTH_TOKEN_KEY = 'auth_token';
export const authService = {
/**
* 获取当前用户(预留,目前返回默认用户)
*/
getCurrentUser(): AuthUser | null {
// TODO: 从 token 解析用户信息
return { id: 'default' };
},
/**
* 获取认证 token预留
*/
getToken(): string | null {
return localStorage.getItem(AUTH_TOKEN_KEY);
},
/**
* 设置 token预留
*/
setToken(token: string): void {
localStorage.setItem(AUTH_TOKEN_KEY, token);
},
/**
* 清除认证信息(预留)
*/
clearAuth(): void {
localStorage.removeItem(AUTH_TOKEN_KEY);
},
/**
* 检查是否已认证(预留,目前始终返回 true
*/
isAuthenticated(): boolean {
// TODO: 实现真实的认证检查
return true;
},
/**
* 获取 Authorization header 值
*/
getAuthHeader(): Record<string, string> {
const token = this.getToken();
if (token) {
return { Authorization: `Bearer ${token}` };
}
return {};
}
};