import type { authModels, OAUTH_TYPE } from '@cloudbase/oauth' import { AuthError } from '@cloudbase/oauth' export interface SignInAnonymouslyReq { provider_token?: string // 提供令牌 } export declare type User = { id: any // 用户ID aud: string // 受众 role: string[] // 用户角色 email: any // 邮箱 email_confirmed_at: string // 邮箱确认时间 phone: any // 手机号 phone_confirmed_at: string // 手机号确认时间 confirmed_at: string // 确认时间 last_sign_in_at: string // 最后登录时间 app_metadata: { // 应用元数据 provider: any // 提供商 providers: any[] // 提供商列表 } user_metadata: { // 用户元数据 name: any // 姓名 picture: any // 头像 username: any // 用户名 gender: any // 性别 locale: any // 地区 uid: any // 用户ID nickName: any // 昵称 avatarUrl: any // 头像URL location: any // 位置 hasPassword: any // 是否有密码 } identities: any // 身份信息 created_at: string // 创建时间 updated_at: string // 更新时间 is_anonymous: boolean // 是否匿名用户 } export declare type Session = { access_token?: string // 访问令牌 refresh_token?: string // 刷新令牌 expires_in?: number // 过期时间(秒) token_type?: string // 令牌类型 user: User // 用户信息 } export interface SignInWithPasswordReq { username?: string // 用户名称(可选,与邮箱、手机号三选一),长度 5-24 位,支持字符中英文、数字、特殊字符(仅支持_-),不支持中文 email?: string // 邮箱(可选,与用户名、手机号三选一) phone?: string // 手机号(可选,与用户名、邮箱三选一) password: string // 密码(必填) is_encrypt?: boolean // 是否加密,默认为false } // 通用响应类型 export interface CommonRes { data: {} // 成功时为空对象 error: AuthError | null // 错误信息,成功时为null } export interface SignInRes { data: { user?: User // 用户信息 session?: Session // 会话信息 } error: AuthError | null // 错误信息,成功时为null } export interface GetUserRes { data: { user?: User // 用户详细信息 } error: AuthError | null // 错误信息,成功时为null } // 更新用户验证回调参数 export interface UpdateUserVerifyOtpParams { email?: string // 邮箱(可选,与手机号二选一) phone?: string // 手机号(可选,与邮箱二选一) token: string // 验证码(必填) } // 更新用户验证回调类型 declare type UpdateUserVerifyCallback = (params: UpdateUserVerifyOtpParams) => Promise // 更新用户响应类型(当需要验证时) export interface UpdateUserWithVerificationRes { data: { verifyOtp?: UpdateUserVerifyCallback // 验证码回调函数 messageId?: string // 验证码ID } error: AuthError | null // 错误信息,成功时为null } export interface SignInWithIdTokenReq { provider?: string // 第三方平台标识(可选) token: string // 第三方平台的身份令牌(必填) } export interface SignInWithOAuthReq { provider: string // 第三方平台标识(必填) options?: { // 配置选项(可选) redirectTo?: string // 回调地址,默认为当前页面 skipBrowserRedirect?: boolean // 是否跳转至授权页面,默认为false state?: string // 状态参数,用于安全验证,默认为随机字符串(格式:prd-{provider}-{随机字符串}) queryParams?: Record // 额外的查询参数,将合并到授权 URI 中 type?: (typeof OAUTH_TYPE)[keyof typeof OAUTH_TYPE] // 类型(可选),默认为'sign_in', sign_in: 登录,bind_identity: 绑定身份 } } export interface SignInOAuthRes { data: { url?: string // 授权页面URL provider?: string // 第三方平台标识 scopes?: string // 授权范围 } error: AuthError | null // 错误信息,成功时为null } export interface GetClaimsRes { data: { // 令牌声明信息 claims?: { iss: string // issuer sub: string // subject aud: string // audience exp: number // expiration time iat: number // issued at at_hash: string // access token hash name: string // 名称 picture?: string // 头像URL email?: string // 邮箱 phone_number?: string // 手机号 scope: string // 授权范围 project_id: string // 项目ID provider?: string // 第三方平台标识 provider_type?: string // 第三方平台类型 groups?: string[] // 用户组 meta?: { wxOpenId?: string wxUnionId?: string } user_id: string // 用户ID roles: string[] // 角色 user_type: string // 用户类型 client_type: string // 客户端类型 is_system_admin: boolean // 是否系统管理员 } // 令牌头部信息 header?: { alg: string // 加密算法 kid: string // 令牌ID } signature?: string // 令牌签名 } error: AuthError | null // 错误信息,成功时为null } export interface UpdateUserReq extends authModels.ModifyUserBasicInfoRequest { email?: string // 邮箱(可选) phone?: string // 手机号(可选) username?: string // 用户名称(可选),长度 5-24 位,支持字符中英文、数字、特殊字符(仅支持_-),不支持中文 description?: string // 描述(可选) avatar_url?: string // 头像URL(可选) nickname?: string // 昵称(可选) gender?: 'MALE' | 'FEMALE' // 性别(可选) } export interface GetUserIdentitiesRes { data: { identities?: | Array<{ id: string // 身份源标识 name: string // 身份源名称 picture: string // 头像URL }> } error: AuthError | null // 错误信息,成功时为null } export interface LinkIdentityReq { provider: string // 身份源标识(必填) } export interface UnlinkIdentityReq { provider: string // 身份源标识(必填) } export interface LinkIdentityRes { data: { provider?: string // 绑定的身份源标识 type?: (typeof OAUTH_TYPE)[keyof typeof OAUTH_TYPE] // 类型(可选),默认为'sign_in', sign_in: 登录,bind_identity: 绑定身份 } error: AuthError | null // 错误信息,成功时为null } export declare type OnAuthStateChangeEvent = | 'SIGNED_OUT' // 用户已登出 | 'SIGNED_IN' // 用户登录成功 | 'INITIAL_SESSION' // 初始会话已建立 | 'PASSWORD_RECOVERY' // 密码已重置 | 'TOKEN_REFRESHED' // 令牌已刷新 | 'USER_UPDATED' // 用户信息已更新 | 'BIND_IDENTITY' // 身份源绑定结果 export declare type OnAuthStateChangeCallback = ( event: OnAuthStateChangeEvent, session: Session, info?: Record, ) => void type MobileOtpType = 'sms' | 'phone_change' type EmailOtpType = 'signup' | 'invite' | 'magiclink' | 'recovery' | 'email_change' | 'email' export interface VerifyOtpReq { type?: MobileOtpType | EmailOtpType email?: string // 邮箱(可选,与手机号二选一) phone?: string // 手机号(可选,与邮箱二选一) token: string // 验证码(必填) messageId?: string // 验证码对应ID(可选) } export interface SignInWithOtpReq { email?: string // 邮箱(可选,与手机号二选一) phone?: string // 手机号(可选,与邮箱二选一) } /** * * @param code 验证码 * @param messageId 可选,ResendRes.data.messageId * @returns */ declare type OtpCallback = (params: VerifyOtpReq) => Promise export interface SignInWithOtpRes { data: SignInRes['data'] & { verifyOtp?: OtpCallback // 验证码回调函数,支持messageId参数 } error: AuthError | null // 错误信息,成功时为null } export interface SignUpRes { data: { verifyOtp?: OtpCallback // 验证码回调函数,支持messageId参数 } error: AuthError | null } export interface ResendReq { email?: string // 邮箱(可选,与手机号二选一) phone?: string // 手机号(可选,与邮箱二选一) type?: 'signup' | 'email_change' | 'phone_change' | 'sms' // 类型(可选) } export interface ResendRes { data: { messageId?: string // 消息ID(验证码ID) } error: AuthError | null // 错误信息,成功时为null } export interface VerifyOAuthReq { code?: string // 授权码(可选,默认从URL参数获取) state?: string // 状态参数(可选,默认从URL参数获取) provider?: string // 第三方平台标识(可选,默认从session获取) } export interface UpdateUserAttributes { nonce: string // 验证码 password: string // 新密码 } // 重置密码响应类型 export interface ResetPasswordForEmailRes { data: { updateUser?: (attributes: UpdateUserAttributes) => Promise // 验证码回调函数,支持新密码参数 } error: AuthError | null // 错误信息,成功时为null } // 重新认证响应类型 export interface ReauthenticateRes { data: { updateUser?: (attributes: UpdateUserAttributes) => Promise // 验证码回调函数,支持新密码参数 } error: AuthError | null // 错误信息,成功时为null } export interface SetSessionReq { access_token: string // 访问令牌 refresh_token: string // 刷新令牌 } export interface DeleteMeReq { password: string // 用户密码 } export interface ResetPasswordForOldReq { old_password: string // 旧密码 new_password: string // 新密码 }