feat(image): 新建 knowai-core:1.0.0 镜像并完成推送
Some checks reported errors
continuous-integration/drone/push Build was killed
Some checks reported errors
continuous-integration/drone/push Build was killed
- 搭建 api、auth、utils 等逻辑模块 - 通过 tsc、eslint、vitest 测试验证 BREAKING CHANGE: 新镜像分支
This commit is contained in:
85
auth/types.d.ts
vendored
Normal file
85
auth/types.d.ts
vendored
Normal file
@@ -0,0 +1,85 @@
|
||||
/**
|
||||
* 认证模块类型定义
|
||||
*/
|
||||
|
||||
import type { AxiosRequestConfig } from 'axios';
|
||||
import type { User } from '@/types';
|
||||
import type {
|
||||
LoginRequest,
|
||||
LoginResponse,
|
||||
RegisterRequest,
|
||||
RegisterResponse
|
||||
} from '@/types/user';
|
||||
|
||||
// 事件类型定义
|
||||
export type AuthEventType = 'login' | 'logout' | 'register' | 'session_expired' | 'session_authenticated' | 'session_logout';
|
||||
|
||||
// 事件监听器类型
|
||||
export type AuthEventListener = (...args: unknown[]) => void;
|
||||
|
||||
// 存储适配器接口 - 仅用于非敏感数据存储,不涉及session管理
|
||||
export interface StorageAdapter {
|
||||
/**
|
||||
* 获取存储项
|
||||
* @param key 存储键
|
||||
* @returns 存储值或null
|
||||
*/
|
||||
getItem(key: string): string | null;
|
||||
|
||||
/**
|
||||
* 设置存储项
|
||||
* @param key 存储键
|
||||
* @param value 存储值
|
||||
*/
|
||||
setItem(key: string, value: string): void;
|
||||
|
||||
/**
|
||||
* 删除存储项
|
||||
* @param key 存储键
|
||||
*/
|
||||
removeItem(key: string): void;
|
||||
|
||||
/**
|
||||
* 清空所有存储项
|
||||
*/
|
||||
clear(): void;
|
||||
|
||||
/**
|
||||
* 获取所有存储键
|
||||
* @returns 存储键数组
|
||||
*/
|
||||
keys(): string[];
|
||||
}
|
||||
|
||||
// 认证服务接口
|
||||
export interface AuthService {
|
||||
login(credentials: LoginRequest): Promise<LoginResponse>;
|
||||
register(userData: RegisterRequest): Promise<RegisterResponse>;
|
||||
logout(): Promise<void>;
|
||||
getCurrentUser(): Promise<User>;
|
||||
isAuthenticated(): Promise<boolean>; // 改为异步,通过getUser验证
|
||||
|
||||
// 事件管理方法
|
||||
on(event: AuthEventType, listener: AuthEventListener): void;
|
||||
off(event: AuthEventType, listener: AuthEventListener): void;
|
||||
|
||||
// 会话管理方法
|
||||
clearCache(): void;
|
||||
}
|
||||
|
||||
// 会话管理器接口 - 仅作为状态查询器,不主动管理session
|
||||
export interface SessionManager {
|
||||
// 通过getUser验证用户认证状态,而不是直接访问cookie
|
||||
isAuthenticated(): Promise<boolean>;
|
||||
// 获取当前用户信息,幂等操作
|
||||
getUserInfo(): Promise<User | null>;
|
||||
// 清除本地缓存,不影响服务器端session
|
||||
clearCache(): void;
|
||||
}
|
||||
|
||||
// 扩展 Axios 请求配置以支持认证选项
|
||||
declare module 'axios' {
|
||||
interface AxiosRequestConfig {
|
||||
skipAuth?: boolean;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user