UNPKG

@cloudbase/types

Version:
79 lines (74 loc) 2.5 kB
import { ICloudbaseConfig, KV, ICloudbase } from '.' export type ICloudbaseAuthConfig = Pick<ICloudbaseConfig, 'env' | 'clientId' | 'region' | 'persistence' | 'debug' | '_fromApp' | 'oauthInstance' | 'wxCloud' | 'i18n' | 'accessKey' | 'useWxCloud'>; export interface IAccessTokenInfo { accessToken: string; env: string; } export interface ICredential { // refreshToken: string; accessToken?: string; accessTokenExpire?: string; } export interface IAuthProvider { signInWithRedirect: () => any; } export interface IUserInfo { uid?: string; loginType?: string; openid?: string; wxOpenId?: string; wxPublicId?: string; unionId?: string; qqMiniOpenId?: string; customUserId?: string; name?: string; gender?: string; email?: string; username?: string; hasPassword?: boolean; location?: { country?: string; province?: string; city?: string; }; country?: string; province?: string; city?: string; } export interface IUser extends IUserInfo { checkLocalInfo: () => void; checkLocalInfoAsync: () => Promise<void>; linkWithTicket?: (ticket: string) => Promise<void>; linkWithRedirect?: (provider: IAuthProvider) => void; getLinkedUidList?: () => Promise<{ hasPrimaryUid: boolean, users: IUserInfo[] }>; setPrimaryUid?: (uid: string) => Promise<void>; unlink?: (loginType: 'CUSTOM' | 'WECHAT-OPEN' | 'WECHAT-PUBLIC' | 'WECHAT-UNION') => Promise<void>; update: (userinfo: IUserInfo) => Promise<void>; refresh: (params?: {version?: string;}) => Promise<IUserInfo>; } export interface ILoginState { user: IUser; } export interface ICloudbaseAuth { config: ICloudbaseConfig; loginType: string; weixinAuthProvider: any; anonymousAuthProvider: any; customAuthProvider: any; getAccessToken: () => IAccessTokenInfo; getLoginState: () => Promise<ILoginState | null>; hasLoginState: () => Promise<ILoginState | null>; getUserInfo: () => Promise<any>; getAuthHeader: () => Promise<KV<string>>; onLoginStateChanged: (callback: Function) => void; onLoginStateExpired: (callback: Function) => void; onAccessTokenRefreshed: (callback: Function) => void; onAnonymousConverted: (callback: Function) => void; onLoginTypeChanged: (callback: Function) => void; shouldRefreshAccessToken: (hook: Function) => void; } type IProvider = new (...args: any[]) => any; export interface ICloudbaseAuthModule { registerAuth: (app: ICloudbase) => void, registerProvider: (name: string, provider: IProvider) => void; }