import { Context } from '@nocobase/actions'; import { Model } from '@nocobase/database'; export type AuthConfig = { authenticator: Model; options: { [key: string]: any; }; ctx: Context; }; export type AuthExtend = new (config: AuthConfig) => T; interface IAuth { user: Model; // Check the authenticaiton status and return the current user. check(): Promise; signIn(): Promise; signUp(): Promise; signOut(): Promise; } export abstract class Auth implements IAuth { abstract user: Model; protected authenticator: Model; protected options: { [key: string]: any; }; protected ctx: Context; constructor(config: AuthConfig) { const { authenticator, options, ctx } = config; this.authenticator = authenticator; this.options = options; this.ctx = ctx; } // The abstract methods are required to be implemented by all authentications. abstract check(); // The following methods are mainly designed for user authentications. async signIn(): Promise {} async signUp(): Promise {} async signOut(): Promise {} }