mirror of
https://gitee.com/nocobase/nocobase.git
synced 2025-07-01 18:52:20 +08:00
* refactor(auth): auth client api * fix: build * fix: dependencies * fix: fix T-2777 * fix: fix T-2776 * chore: update type * fix: build * fix: allowSignUp * fix: file name * fix: file name * refactor: client api * fix: build * chore: update name * fix: tsx must be loaded with --import instead of --loader * fix: type * fix: type * fix: type * fix: type * fix: bug * chore: improve wording * fix: test --------- Co-authored-by: chenos <chenlinxh@gmail.com>
70 lines
2.0 KiB
TypeScript
70 lines
2.0 KiB
TypeScript
import { Plugin } from '@nocobase/client';
|
|
import { AuthProvider } from './AuthProvider';
|
|
import { NAMESPACE } from './locale';
|
|
import { Authenticator } from './settings/Authenticator';
|
|
import { AuthLayout, SignInPage, SignUpPage } from './pages';
|
|
import { ComponentType } from 'react';
|
|
import { Registry } from '@nocobase/utils/client';
|
|
import { presetAuthType } from '../preset';
|
|
import { SignInForm, SignUpForm, Options } from './basic';
|
|
import { Authenticator as AuthenticatorType } from './authenticator';
|
|
|
|
export type AuthOptions = {
|
|
components: Partial<{
|
|
SignInForm: ComponentType<{ authenticator: AuthenticatorType }>;
|
|
SignInButton: ComponentType<{ authenticator: AuthenticatorType }>;
|
|
SignUpForm: ComponentType<{ authenticatorName: string }>;
|
|
AdminSettingsForm: ComponentType;
|
|
}>;
|
|
};
|
|
|
|
export class AuthPlugin extends Plugin {
|
|
authTypes = new Registry<AuthOptions>();
|
|
|
|
registerType(authType: string, options: AuthOptions) {
|
|
this.authTypes.register(authType, options);
|
|
}
|
|
|
|
async load() {
|
|
this.app.pluginSettingsManager.add(NAMESPACE, {
|
|
icon: 'LoginOutlined',
|
|
title: `{{t("Authentication", { ns: "${NAMESPACE}" })}}`,
|
|
Component: Authenticator,
|
|
aclSnippet: 'pm.auth.authenticators',
|
|
});
|
|
|
|
this.router.add('auth', {
|
|
Component: 'AuthLayout',
|
|
});
|
|
this.router.add('auth.signin', {
|
|
path: '/signin',
|
|
Component: 'SignInPage',
|
|
});
|
|
this.router.add('auth.signup', {
|
|
path: '/signup',
|
|
Component: 'SignUpPage',
|
|
});
|
|
|
|
this.app.addComponents({
|
|
AuthLayout,
|
|
SignInPage,
|
|
SignUpPage,
|
|
});
|
|
|
|
this.app.providers.unshift([AuthProvider, {}]);
|
|
|
|
this.registerType(presetAuthType, {
|
|
components: {
|
|
SignInForm: SignInForm,
|
|
SignUpForm: SignUpForm,
|
|
AdminSettingsForm: Options,
|
|
},
|
|
});
|
|
}
|
|
}
|
|
|
|
export default AuthPlugin;
|
|
export { useSignIn } from './basic';
|
|
export { useAuthenticator, AuthenticatorsContext } from './authenticator';
|
|
export type { Authenticator } from './authenticator';
|