docs/docs/cn/api/auth/auth.md
Auth 是用户认证类型的抽象类,定义了完成用户认证需要的接口,扩展新的用户认证类型需要继承 Auth 类,并实现其中的方法。基础实现可以参考: BaseAuth.
interface IAuth {
user: Model;
// Check the authenticaiton status and return the current user.
check(): Promise<Model>;
signIn(): Promise<any>;
signUp(): Promise<any>;
signOut(): Promise<any>;
}
export abstract class Auth implements IAuth {
abstract user: Model;
abstract check(): Promise<Model>;
// ...
}
class CustomAuth extends Auth {
// check: 鉴权
async check() {
// ...
}
}
user认证用户信息。
abstract user: Modelconstructor()构造函数,创建一个 Auth 实例。
constructor(config: AuthConfig)export type AuthConfig = {
authenticator: Authenticator;
options: {
[key: string]: any;
};
ctx: Context;
};
| 属性 | 类型 | 描述 |
|---|---|---|
authenticator | Authenticator | 认证器数据模型,在 NocoBase 应用中的实际类型是 AuthModel |
options | Record<string, any> | 认证器相关配置 |
ctx | Context | 请求上下文 |
check()用户鉴权,返回用户信息,所有认证类型都必须实现的抽象方法。
abstract check(): Promise<Model>signIn()用户登录。
signIn(): Promise<any>signUp()用户注册。
signUp(): Promise<any>signOut()用户注销登录。
signOut(): Promise<any>