docs/docs/en/auth-verification/auth/dev/api.md
Kernel API, reference: Auth
Kernel API, reference: BaseAuth
AuthModel is the authenticator used in NocoBase applications (Authenticator, reference: AuthManager - setStorer and Auth - constructor) data model, providing some methods for interacting with the user data collection. In addition, methods provided by Sequelize Model can also be used.
import { AuthModel } from '@nocobase/plugin-auth';
class CustomAuth extends BaseAuth {
async validate() {
// ...
const authenticator = this.authenticator as AuthModel;
this.authenticator.findUser();
this.authenticator.newUser();
this.authenticator.findOrCreateUser();
// ...
}
}
findUser(uuid: string): UserModel - Query user by uuid.
uuid - User unique identifier from the current authentication typenewUser(uuid: string, userValues?: any): UserModel - Create a new user, bind the user to the current authenticator through uuid.
uuid - User unique identifier from the current authentication typeuserValues - Optional. Other user information. When not passed, uuid will be used as the user's nickname.findOrCreateUser(uuid: string, userValues?: any): UserModel - Find or create a new user, the creation rule is the same as above.
uuid - User unique identifier from the current authentication typeuserValues - Optional. Other user information.plugin.registerType()Register the client of the authentication type.
import AuthPlugin from '@nocobase/plugin-auth/client';
class CustomAuthPlugin extends Plugin {
async load() {
const auth = this.app.pm.get(AuthPlugin);
auth.registerType('custom-auth-type', {
components: {
SignInForm,
// SignInButton
SignUpForm,
AdminSettingsForm,
},
});
}
}
registerType(authType: string, options: AuthOptions)export type AuthOptions = {
components: Partial<{
SignInForm: ComponentType<{ authenticator: AuthenticatorType }>;
SignInButton: ComponentType<{ authenticator: AuthenticatorType }>;
SignUpForm: ComponentType<{ authenticatorName: string }>;
AdminSettingsForm: ComponentType;
}>;
};
SignInForm - Sign in formSignInButton - Sign in (third-party) button, can be used as an alternative to the sign-in formSignUpForm - Sign up formAdminSettingsForm - Admin configuration formThe frontend routes for registering the auth plugin are as follows:
Auth Layout
auth-AuthLayoutSignIn Page
auth.signin/signinSignInPageSignUp Page
auth.signup/signupSignUpPage