Your Name 23835ee790 feat: 前端对接后端认证 API
API 客户端更新:
- 添加双 Token JWT 认证支持
- 添加 401 自动刷新 Token 机制
- 添加注册/登录/刷新 Token API
- 添加 OSS 上传凭证 API

AuthContext 更新:
- 支持真实 API 认证
- 保留开发模式 Mock 数据
- 添加 register 方法

类型定义更新:
- User 类型添加组织关联字段
- 添加 LoginCredentials、RegisterData 类型

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-02-09 13:49:07 +08:00

49 lines
1011 B
TypeScript

/**
* 认证相关类型定义
* 注意:这些类型应与 @/lib/api 中的类型保持一致
*/
export type UserRole = 'creator' | 'agency' | 'brand'
export interface User {
id: string
email?: string
phone?: string
name: string
avatar?: string
role: UserRole
is_verified: boolean
brand_id?: string
agency_id?: string
creator_id?: string
tenant_id?: string
tenant_name?: string
}
export interface LoginCredentials {
email?: string
phone?: string
password: string
}
export interface RegisterData {
email?: string
phone?: string
password: string
name: string
role: UserRole
}
export interface AuthState {
user: User | null
isAuthenticated: boolean
isLoading: boolean
}
export interface AuthContextType extends AuthState {
login: (credentials: LoginCredentials) => Promise<{ success: boolean; error?: string }>
register: (data: RegisterData) => Promise<{ success: boolean; error?: string }>
logout: () => void
switchRole: (role: UserRole) => void
}