@nocobase/plugin-auth 0.17.0-alpha.6 → 0.18.0-alpha.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/client/authenticator.d.ts +13 -0
- package/dist/client/basic/SignInForm.d.ts +9 -0
- package/dist/client/basic/SignUpForm.d.ts +13 -0
- package/dist/client/basic/index.d.ts +3 -0
- package/dist/client/index.d.ts +21 -0
- package/dist/client/index.js +12 -2
- package/dist/client/pages/AuthLayout.d.ts +2 -0
- package/dist/client/pages/SignInPage.d.ts +16 -0
- package/dist/client/pages/SignUpPage.d.ts +21 -0
- package/dist/client/pages/index.d.ts +3 -0
- package/dist/client/settings/Options.d.ts +3 -2
- package/dist/externalVersion.js +14 -12
- package/dist/locale/en-US.json +4 -1
- package/dist/locale/zh-CN.json +4 -1
- package/dist/node_modules/cron/LICENSE +0 -0
- package/dist/node_modules/cron/lib/cron.js +1 -1
- package/dist/node_modules/cron/lib/job.js +0 -0
- package/dist/node_modules/cron/lib/time.js +33 -20
- package/dist/node_modules/cron/node_modules/luxon/build/amd/luxon.js +7826 -0
- package/dist/node_modules/cron/node_modules/luxon/build/cjs-browser/luxon.js +7824 -0
- package/dist/node_modules/cron/node_modules/luxon/build/es6/luxon.js +7217 -0
- package/dist/node_modules/cron/node_modules/luxon/build/global/luxon.js +7829 -0
- package/dist/node_modules/cron/node_modules/luxon/build/global/luxon.min.js +1 -0
- package/dist/node_modules/cron/node_modules/luxon/build/node/luxon.js +6932 -0
- package/dist/node_modules/cron/node_modules/luxon/package.json +85 -0
- package/dist/node_modules/cron/node_modules/luxon/src/datetime.js +2248 -0
- package/dist/node_modules/cron/node_modules/luxon/src/duration.js +948 -0
- package/dist/node_modules/cron/node_modules/luxon/src/errors.js +61 -0
- package/dist/node_modules/cron/node_modules/luxon/src/impl/conversions.js +161 -0
- package/dist/node_modules/cron/node_modules/luxon/src/impl/diff.js +75 -0
- package/dist/node_modules/cron/node_modules/luxon/src/impl/digits.js +75 -0
- package/dist/node_modules/cron/node_modules/luxon/src/impl/english.js +233 -0
- package/dist/node_modules/cron/node_modules/luxon/src/impl/formats.js +176 -0
- package/dist/node_modules/cron/node_modules/luxon/src/impl/formatter.js +400 -0
- package/dist/node_modules/cron/node_modules/luxon/src/impl/invalid.js +14 -0
- package/dist/node_modules/cron/node_modules/luxon/src/impl/locale.js +494 -0
- package/dist/node_modules/cron/node_modules/luxon/src/impl/regexParser.js +335 -0
- package/dist/node_modules/cron/node_modules/luxon/src/impl/tokenParser.js +444 -0
- package/dist/node_modules/cron/node_modules/luxon/src/impl/util.js +274 -0
- package/dist/node_modules/cron/node_modules/luxon/src/impl/zoneUtil.js +34 -0
- package/dist/node_modules/cron/node_modules/luxon/src/info.js +169 -0
- package/dist/node_modules/cron/node_modules/luxon/src/interval.js +637 -0
- package/dist/node_modules/cron/node_modules/luxon/src/luxon.js +26 -0
- package/dist/node_modules/cron/node_modules/luxon/src/package.json +4 -0
- package/dist/node_modules/cron/node_modules/luxon/src/settings.js +148 -0
- package/dist/node_modules/cron/node_modules/luxon/src/zone.js +91 -0
- package/dist/node_modules/cron/node_modules/luxon/src/zones/IANAZone.js +189 -0
- package/dist/node_modules/cron/node_modules/luxon/src/zones/fixedOffsetZone.js +102 -0
- package/dist/node_modules/cron/node_modules/luxon/src/zones/invalidZone.js +53 -0
- package/dist/node_modules/cron/node_modules/luxon/src/zones/systemZone.js +61 -0
- package/dist/node_modules/cron/package.json +1 -1
- package/dist/node_modules/cron/types/index.d.ts +181 -0
- package/dist/node_modules/cron/types/index.test-d.ts +85 -0
- package/dist/server/actions/authenticators.js +3 -0
- package/dist/server/basic-auth.js +5 -2
- package/dist/server/migrations/20231218132032-fix-allow-signup.d.ts +5 -0
- package/dist/server/migrations/20231218132032-fix-allow-signup.js +54 -0
- package/dist/server/model/authenticator.d.ts +5 -2
- package/dist/server/model/authenticator.js +2 -2
- package/package.json +2 -2
- package/dist/client/AuthPluginProvider.d.ts +0 -2
- package/dist/client/basic/SigninPage.d.ts +0 -6
- package/dist/client/basic/SignupPage.d.ts +0 -5
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/// <reference types="react" />
|
|
2
|
+
export type Authenticator = {
|
|
3
|
+
name: string;
|
|
4
|
+
authType: string;
|
|
5
|
+
authTypeTitle: string;
|
|
6
|
+
title?: string;
|
|
7
|
+
options?: {
|
|
8
|
+
[key: string]: any;
|
|
9
|
+
};
|
|
10
|
+
sort?: number;
|
|
11
|
+
};
|
|
12
|
+
export declare const AuthenticatorsContext: import("react").Context<Authenticator[]>;
|
|
13
|
+
export declare const useAuthenticator: (name: string) => Authenticator;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { Authenticator } from '../authenticator';
|
|
3
|
+
export declare function useRedirect(next?: string): () => void;
|
|
4
|
+
export declare const useSignIn: (authenticator: string) => {
|
|
5
|
+
run(): Promise<void>;
|
|
6
|
+
};
|
|
7
|
+
export declare const SignInForm: (props: {
|
|
8
|
+
authenticator: Authenticator;
|
|
9
|
+
}) => React.JSX.Element;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
export interface UseSignupProps {
|
|
3
|
+
authenticator?: string;
|
|
4
|
+
message?: {
|
|
5
|
+
success?: string;
|
|
6
|
+
};
|
|
7
|
+
}
|
|
8
|
+
export declare const useSignUp: (props?: UseSignupProps) => {
|
|
9
|
+
run(): Promise<void>;
|
|
10
|
+
};
|
|
11
|
+
export declare const SignUpForm: ({ authenticatorName: name }: {
|
|
12
|
+
authenticatorName: string;
|
|
13
|
+
}) => React.JSX.Element;
|
package/dist/client/index.d.ts
CHANGED
|
@@ -1,5 +1,26 @@
|
|
|
1
1
|
import { Plugin } from '@nocobase/client';
|
|
2
|
+
import { ComponentType } from 'react';
|
|
3
|
+
import { Authenticator as AuthenticatorType } from './authenticator';
|
|
4
|
+
export type AuthOptions = {
|
|
5
|
+
components: Partial<{
|
|
6
|
+
SignInForm: ComponentType<{
|
|
7
|
+
authenticator: AuthenticatorType;
|
|
8
|
+
}>;
|
|
9
|
+
SignInButton: ComponentType<{
|
|
10
|
+
authenticator: AuthenticatorType;
|
|
11
|
+
}>;
|
|
12
|
+
SignUpForm: ComponentType<{
|
|
13
|
+
authenticatorName: string;
|
|
14
|
+
}>;
|
|
15
|
+
AdminSettingsForm: ComponentType;
|
|
16
|
+
}>;
|
|
17
|
+
};
|
|
2
18
|
export declare class AuthPlugin extends Plugin {
|
|
19
|
+
authTypes: any;
|
|
20
|
+
registerType(authType: string, options: AuthOptions): void;
|
|
3
21
|
load(): Promise<void>;
|
|
4
22
|
}
|
|
5
23
|
export default AuthPlugin;
|
|
24
|
+
export { useSignIn } from './basic';
|
|
25
|
+
export { useAuthenticator, AuthenticatorsContext } from './authenticator';
|
|
26
|
+
export type { Authenticator } from './authenticator';
|
package/dist/client/index.js
CHANGED
|
@@ -1,4 +1,14 @@
|
|
|
1
|
-
(function(
|
|
1
|
+
(function(c,e){typeof exports=="object"&&typeof module!="undefined"?e(exports,require("@nocobase/client"),require("react/jsx-runtime"),require("react"),require("react-router-dom"),require("react-i18next"),require("antd"),require("@formily/shared"),require("@ant-design/icons"),require("@formily/react"),require("@emotion/css"),require("@nocobase/utils/client")):typeof define=="function"&&define.amd?define(["exports","@nocobase/client","react/jsx-runtime","react","react-router-dom","react-i18next","antd","@formily/shared","@ant-design/icons","@formily/react","@emotion/css","@nocobase/utils/client"],e):(c=typeof globalThis!="undefined"?globalThis:c||self,e(c["@nocobase/plugin-auth"]={},c["@nocobase/client"],c.jsxRuntime,c.react,c["react-router-dom"],c["react-i18next"],c.antd,c["@formily/shared"],c["@ant-design/icons"],c["@formily/react"],c["@emotion/css"],c["@nocobase/utils"]))})(this,function(c,e,n,u,m,x,d,g,y,h,b,E){"use strict";var ae=Object.defineProperty,pe=Object.defineProperties;var ue=Object.getOwnPropertyDescriptors;var $=Object.getOwnPropertySymbols;var le=Object.prototype.hasOwnProperty,me=Object.prototype.propertyIsEnumerable;var P=(c,e,n)=>e in c?ae(c,e,{enumerable:!0,configurable:!0,writable:!0,value:n}):c[e]=n,v=(c,e)=>{for(var n in e||(e={}))le.call(e,n)&&P(c,n,e[n]);if($)for(var n of $(e))me.call(e,n)&&P(c,n,e[n]);return c},T=(c,e)=>pe(c,ue(e));var N=(c,e,n)=>(P(c,typeof e!="symbol"?e+"":e,n),n);var C=(c,e,n)=>new Promise((u,m)=>{var x=y=>{try{g(n.next(y))}catch(h){m(h)}},d=y=>{try{g(n.throw(y))}catch(h){m(h)}},g=y=>y.done?u(y.value):Promise.resolve(y.value).then(x,d);g((n=n.apply(c,e)).next())});const j=t=>{const r=m.useLocation(),o=e.useAPIClient();return u.useEffect(()=>{const i=new URLSearchParams(r.search),s=i.get("authenticator"),a=i.get("token");a&&(o.auth.setToken(a),o.auth.setAuthenticator(s))}),n.jsx(n.Fragment,{children:t.children})},F="auth";function A(){return x.useTranslation([F,"client"],{nsMode:"fallback"})}const I=u.createContext({type:""}),U=u.createContext({types:[]}),B=()=>{const{types:t}=u.useContext(U);return t},k={name:"authenticators",sortable:!0,fields:[{name:"id",type:"string",interface:"id"},{interface:"input",type:"string",name:"name",uiSchema:{type:"string",title:'{{t("Auth UID")}}',"x-component":"Input","x-validator":t=>/^[a-zA-Z0-9_-]+$/.test(t)?"":e.i18n.t("a-z, A-Z, 0-9, _, -"),required:!0}},{interface:"input",type:"string",name:"authType",uiSchema:{type:"string",title:'{{t("Auth Type")}}',"x-component":"Select",dataSource:"{{ types }}",required:!0}},{interface:"input",type:"string",name:"title",uiSchema:{type:"string",title:'{{t("Title")}}',"x-component":"Input"}},{interface:"textarea",type:"string",name:"description",uiSchema:{type:"string",title:'{{t("Description")}}',"x-component":"Input"}},{type:"boolean",name:"enabled",uiSchema:{type:"boolean",title:'{{t("Enabled")}}',"x-component":"Checkbox"}}]},L={type:"object",properties:{drawer:{type:"void","x-component":"Action.Drawer","x-decorator":"Form","x-decorator-props":{useValues(t){const r=e.useActionContext(),{type:o}=u.useContext(I);return e.useRequest(()=>Promise.resolve({data:{name:`s_${g.uid()}`,authType:o}}),T(v({},t),{refreshDeps:[r.visible]}))}},title:'{{t("Add new")}}',properties:{name:{"x-component":"CollectionField","x-decorator":"FormItem"},authType:{"x-component":"CollectionField","x-decorator":"FormItem","x-component-props":{options:"{{ types }}"}},title:{"x-component":"CollectionField","x-decorator":"FormItem"},description:{"x-component":"CollectionField","x-decorator":"FormItem"},enabled:{"x-component":"CollectionField","x-decorator":"FormItem"},options:{type:"object","x-component":"Options"},footer:{type:"void","x-component":"Action.Drawer.Footer",properties:{cancel:{title:'{{t("Cancel")}}',"x-component":"Action","x-component-props":{useAction:"{{ cm.useCancelAction }}"}},submit:{title:'{{t("Submit")}}',"x-component":"Action","x-component-props":{type:"primary",useAction:"{{ cm.useCreateAction }}"}}}}}}}},O={type:"void",name:"authenticators","x-decorator":"ResourceActionProvider","x-decorator-props":{collection:k,resourceName:"authenticators",dragSort:!0,request:{resource:"authenticators",action:"list",params:{pageSize:50,sort:"sort",appends:[]}}},"x-component":"CollectionProvider","x-component-props":{collection:k},properties:{actions:{type:"void","x-component":"ActionBar","x-component-props":{style:{marginBottom:16}},properties:{delete:{type:"void",title:'{{t("Delete")}}',"x-component":"Action","x-component-props":{useAction:"{{ cm.useBulkDestroyAction }}",confirm:{title:"{{t('Delete')}}",content:"{{t('Are you sure you want to delete it?')}}"}}},create:{type:"void",title:'{{t("Add new")}}',"x-component":"AddNew","x-component-props":{type:"primary"}}}},table:{type:"void","x-uid":"input","x-component":"Table.Void","x-component-props":{rowKey:"id",rowSelection:{type:"checkbox"},useDataSource:"{{ cm.useDataSourceFromRAC }}",useAction(){const t=e.useAPIClient(),{t:r}=x.useTranslation();return{move(i,s){return C(this,null,function*(){yield t.resource("authenticators").move({sourceId:i.id,targetId:s.id}),d.message.success(r("Saved successfully"),.2)})}}}},properties:{id:{type:"void","x-decorator":"Table.Column.Decorator","x-component":"Table.Column",properties:{id:{type:"number","x-component":"CollectionField","x-read-pretty":!0}}},name:{type:"void","x-decorator":"Table.Column.Decorator","x-component":"Table.Column",properties:{name:{type:"string","x-component":"CollectionField","x-read-pretty":!0}}},authType:{title:'{{t("Auth Type")}}',type:"void","x-decorator":"Table.Column.Decorator","x-component":"Table.Column",properties:{authType:{type:"string","x-component":"Select","x-read-pretty":!0,enum:"{{ types }}"}}},title:{type:"void","x-decorator":"Table.Column.Decorator","x-component":"Table.Column",properties:{title:{type:"string","x-component":"CollectionField","x-read-pretty":!0}}},description:{type:"void","x-decorator":"Table.Column.Decorator","x-component":"Table.Column",properties:{description:{type:"boolean","x-component":"CollectionField","x-read-pretty":!0}}},enabled:{type:"void","x-decorator":"Table.Column.Decorator","x-component":"Table.Column",properties:{enabled:{type:"boolean","x-component":"CollectionField","x-read-pretty":!0}}},actions:{type:"void",title:'{{t("Actions")}}',"x-component":"Table.Column",properties:{actions:{type:"void","x-component":"Space","x-component-props":{split:"|"},properties:{update:{type:"void",title:'{{t("Configure")}}',"x-component":"Action.Link","x-component-props":{type:"primary"},properties:{drawer:{type:"void","x-component":"Action.Drawer","x-decorator":"Form","x-decorator-props":{useValues:"{{ cm.useValuesFromRecord }}"},title:'{{t("Configure")}}',properties:{name:{"x-component":"CollectionField","x-decorator":"FormItem"},authType:{"x-component":"CollectionField","x-decorator":"FormItem","x-component-props":{options:"{{ types }}"}},title:{"x-component":"CollectionField","x-decorator":"FormItem"},description:{"x-component":"CollectionField","x-decorator":"FormItem"},enabled:{"x-component":"CollectionField","x-decorator":"FormItem"},options:{type:"object","x-component":"Options"},footer:{type:"void","x-component":"Action.Drawer.Footer",properties:{cancel:{title:'{{t("Cancel")}}',"x-component":"Action","x-component-props":{useAction:"{{ cm.useCancelAction }}"}},submit:{title:'{{t("Submit")}}',"x-component":"Action","x-component-props":{type:"primary",useAction:"{{ cm.useUpdateAction }}"}}}}}}}},delete:{type:"void",title:'{{ t("Delete") }}',"x-component":"Action.Link","x-component-props":{confirm:{title:"{{t('Delete record')}}",content:"{{t('Are you sure you want to delete it?')}}"},useAction:"{{cm.useDestroyAction}}"},"x-disabled":"{{ useCanNotDelete() }}"}}}}}}}}},V=t=>{const r=e.useRecord(),o=e.useRequest(()=>Promise.resolve({data:v({},r.options)}),T(v({},t),{manual:!0})),{run:i}=o,s=e.useActionContext();return u.useEffect(()=>{s.visible&&i()},[s.visible,i]),o},_=t=>{var i;const o=e.usePlugin(f).authTypes.get(t);return(i=o==null?void 0:o.components)==null?void 0:i.AdminSettingsForm},M=h.observer(()=>{const t=h.useForm(),r=e.useRecord(),o=_(t.values.authType||r.authType);return o?n.jsx(o,{}):null}),z=()=>{const{setVisible:t}=e.useActionContext();return{run(){return C(this,null,function*(){t(!1)})}}},Z=()=>{const{t}=x.useTranslation(),[r,o]=u.useState(!1),[i,s]=u.useState(""),a=B(),p=a.map(l=>T(v({},l),{onClick:()=>{o(!0),s(l.value)}}));return n.jsx(e.ActionContextProvider,{value:{visible:r,setVisible:o},children:n.jsxs(I.Provider,{value:{type:i},children:[n.jsx(d.Dropdown,{menu:{items:p},children:n.jsxs(d.Button,{icon:n.jsx(y.PlusOutlined,{}),type:"primary",children:[t("Add new")," ",n.jsx(y.DownOutlined,{})]})}),n.jsx(e.SchemaComponent,{scope:{useCloseAction:z,types:a,setType:s},schema:L})]})})},K=()=>(e.useAsyncData(),!1),W=()=>{const{t}=A(),[r,o]=u.useState([]),i=e.useAPIClient();return e.useRequest(()=>i.resource("authenticators").listTypes().then(s=>{var p;return(((p=s==null?void 0:s.data)==null?void 0:p.data)||[]).map(l=>({key:l.name,label:t(l.title||l.name),value:l.name}))}),{onSuccess:s=>{o(s)}}),n.jsx(d.Card,{bordered:!1,children:n.jsx(U.Provider,{value:{types:r},children:n.jsx(e.SchemaComponent,{schema:O,components:{AddNew:Z,Options:M},scope:{types:r,useValuesFromOptions:V,useCanNotDelete:K,t}})})})},S=u.createContext([]),w=t=>u.useContext(S).find(o=>o.name===t);function G(t){var a;const{data:r}=e.useSystemSettings(),o=e.useAPIClient(),{data:i=[],error:s}=e.useRequest(()=>o.resource("authenticators").publicList().then(p=>{var l;return((l=p==null?void 0:p.data)==null?void 0:l.data)||[]}));if(s)throw s;return n.jsxs("div",{style:{maxWidth:320,margin:"0 auto",paddingTop:"20vh"},children:[n.jsx("h1",{children:(a=r==null?void 0:r.data)==null?void 0:a.title}),n.jsx(S.Provider,{value:i,children:n.jsx(m.Outlet,{})}),n.jsx("div",{className:b.css`
|
|
2
|
+
position: absolute;
|
|
3
|
+
bottom: 24px;
|
|
4
|
+
width: 100%;
|
|
5
|
+
left: 0;
|
|
6
|
+
text-align: center;
|
|
7
|
+
`,children:n.jsx(e.PoweredBy,{})})]})}const H=()=>{var i;const r=e.usePlugin(f).authTypes.getEntities(),o={};for(const[s,a]of r)(i=a.components)!=null&&i.SignInForm&&(o[s]=a.components.SignInForm);return o},J=(t=[])=>{var a;const o=e.usePlugin(f).authTypes.getEntities(),i={};for(const[p,l]of o)(a=l.components)!=null&&a.SignInButton&&(i[p]=l.components.SignInButton);const s=Object.keys(i);return t.filter(p=>s.includes(p.authType)).map((p,l)=>u.createElement(i[p.authType],{key:l,authenticator:p}))},Q=()=>{const{t}=A();e.useCurrentDocumentTitle("Signin"),e.useViewport();const r=H(),o=u.useContext(S),i=J(o);if(!o.length)return n.jsx("div",{style:{color:"#ccc"},children:t("No authentication methods available.")});const s=o.map(a=>{const p=r[a.authType];if(!p)return;const l=`${t("Sign-in")} (${t(a.authTypeTitle||a.authType)})`;return v({component:u.createElement(p,{authenticator:a}),tabTitle:a.title||l},a)}).filter(a=>a);return n.jsxs(d.Space,{direction:"vertical",className:b.css`
|
|
8
|
+
display: flex;
|
|
9
|
+
`,children:[s.length>1?n.jsx(d.Tabs,{items:s.map(a=>({label:a.tabTitle,key:a.name,children:a.component}))}):s.length?n.jsx("div",{children:s[0].component}):n.jsx(n.Fragment,{}),n.jsx(d.Space,{direction:"vertical",className:b.css`
|
|
10
|
+
display: flex;
|
|
11
|
+
`,children:i})]})};u.createContext({});const q=()=>{var i;const r=e.usePlugin(f).authTypes.getEntities(),o={};for(const[s,a]of r)(i=a.components)!=null&&i.SignUpForm&&(o[s]=a.components.SignUpForm);return o},X=()=>{e.useViewport(),e.useCurrentDocumentTitle("Signup");const t=q(),[r]=m.useSearchParams(),o=r.get("name"),i=w(o),{authType:s}=i||{};return t[s]?u.createElement(t[s],{authenticatorName:o}):n.jsx(m.Navigate,{to:"/not-found",replace:!0})},Y="Email/Password";function R(t="/admin"){const r=m.useNavigate(),[o]=m.useSearchParams();return u.useCallback(()=>{r(o.get("redirect")||"/admin",{replace:!0})},[r,o])}const D=t=>{const r=h.useForm(),o=e.useAPIClient(),i=R(),{refreshAsync:s}=e.useCurrentUserContext();return{run(){return C(this,null,function*(){yield r.submit(),yield o.auth.signIn(r.values,t),yield s(),i()})}}},ee={type:"object",name:"passwordForm","x-component":"FormV2",properties:{account:{type:"string","x-component":"Input","x-validator":`{{(value) => {
|
|
2
12
|
if (!value) {
|
|
3
13
|
return t("Please enter your username or email");
|
|
4
14
|
}
|
|
@@ -9,4 +19,4 @@
|
|
|
9
19
|
} else {
|
|
10
20
|
return /^[^@.<>"'/]{2,16}$/.test(value) || t("Please enter a valid username");
|
|
11
21
|
}
|
|
12
|
-
}}}`,"x-decorator":"FormItem","x-component-props":{placeholder:'{{t("Username/Email")}}',style:{}}},password:{type:"string","x-component":"Password",required:!0,"x-decorator":"FormItem","x-component-props":{placeholder:'{{t("Password")}}',style:{}}},actions:{type:"void","x-component":"div",properties:{submit:{title:'{{t("Sign in")}}',type:"void","x-component":"Action","x-component-props":{htmlType:"submit",block:!0,type:"primary",useAction:"{{ useBasicSignIn }}",style:{width:"100%"}}}}},signup:{type:"void","x-component":"Link","x-component-props":{to:"{{ signupLink }}"},"x-content":'{{t("Create an account")}}',"x-visible":"{{ allowSignUp }}"}}},$=o=>{const{t:r}=h(),i=o.authenticator,{authType:p,name:s,options:u}=i,m=!!c.useContext(e.SignupPageContext)[p]&&(u==null?void 0:u.allowSignup),G=`/signup?authType=${p}&name=${s}`,H=()=>e.useSignIn(s);return t.jsx(e.SchemaComponent,{schema:q,scope:{useBasicSignIn:H,allowSignUp:m,signupLink:G,t:r}})},j={type:"object",name:A.uid(),"x-component":"FormV2",properties:{username:{type:"string",required:!0,"x-component":"Input","x-validator":{username:!0},"x-decorator":"FormItem","x-component-props":{placeholder:'{{t("Username")}}',style:{}}},password:{type:"string",required:!0,"x-component":"Password","x-decorator":"FormItem","x-component-props":{placeholder:'{{t("Password")}}',checkStrength:!0,style:{}},"x-reactions":[{dependencies:[".confirm_password"],fulfill:{state:{selfErrors:'{{$deps[0] && $self.value && $self.value !== $deps[0] ? t("Password mismatch") : ""}}'}}}]},confirm_password:{type:"string",required:!0,"x-component":"Password","x-decorator":"FormItem","x-component-props":{placeholder:'{{t("Confirm password")}}',style:{}},"x-reactions":[{dependencies:[".password"],fulfill:{state:{selfErrors:'{{$deps[0] && $self.value && $self.value !== $deps[0] ? t("Password mismatch") : ""}}'}}}]},actions:{type:"void","x-component":"div",properties:{submit:{title:'{{t("Sign up")}}',type:"void","x-component":"Action","x-component-props":{block:!0,type:"primary",htmlType:"submit",useAction:"{{ useBasicSignup }}",style:{width:"100%"}}}}},link:{type:"void","x-component":"div",properties:{link:{type:"void","x-component":"Link","x-component-props":{to:"/signin"},"x-content":'{{t("Log in with an existing account")}}'}}}}},O=o=>{const{t:r}=h(),i=()=>e.useSignup({authenticator:o.name});return t.jsx(e.SchemaComponent,{schema:j,scope:{useBasicSignup:i,t:r}})},L=o=>{const{t:r}=h();return t.jsx(e.OptionsComponentProvider,{authType:b,component:k,children:t.jsx(e.SigninPageProvider,{authType:b,tabTitle:r("Sign in via password"),component:$,children:t.jsx(e.SignupPageProvider,{authType:b,component:O,children:o.children})})})},E=o=>{const r=y.useLocation(),i=e.useAPIClient();return c.useEffect(()=>{const p=new URLSearchParams(r.search),s=p.get("authenticator"),u=p.get("token");u&&(i.auth.setToken(u),i.auth.setAuthenticator(s))}),t.jsx(t.Fragment,{children:o.children})},w=c.createContext({type:""}),T=c.createContext({types:[]}),V=()=>{const{types:o}=c.useContext(T);return o},F={name:"authenticators",sortable:!0,fields:[{name:"id",type:"string",interface:"id"},{interface:"input",type:"string",name:"name",uiSchema:{type:"string",title:'{{t("Auth UID")}}',"x-component":"Input","x-validator":o=>/^[a-zA-Z0-9_-]+$/.test(o)?"":e.i18n.t("a-z, A-Z, 0-9, _, -"),required:!0}},{interface:"input",type:"string",name:"authType",uiSchema:{type:"string",title:'{{t("Auth Type")}}',"x-component":"Select",dataSource:"{{ types }}",required:!0}},{interface:"input",type:"string",name:"title",uiSchema:{type:"string",title:'{{t("Title")}}',"x-component":"Input"}},{interface:"textarea",type:"string",name:"description",uiSchema:{type:"string",title:'{{t("Description")}}',"x-component":"Input"}},{type:"boolean",name:"enabled",uiSchema:{type:"boolean",title:'{{t("Enabled")}}',"x-component":"Checkbox"}}]},B={type:"object",properties:{drawer:{type:"void","x-component":"Action.Drawer","x-decorator":"Form","x-decorator-props":{useValues(o){const r=e.useActionContext(),{type:i}=c.useContext(w);return e.useRequest(()=>Promise.resolve({data:{name:`s_${A.uid()}`,authType:i}}),C(g({},o),{refreshDeps:[r.visible]}))}},title:'{{t("Add new")}}',properties:{name:{"x-component":"CollectionField","x-decorator":"FormItem"},authType:{"x-component":"CollectionField","x-decorator":"FormItem","x-component-props":{options:"{{ types }}"}},title:{"x-component":"CollectionField","x-decorator":"FormItem"},description:{"x-component":"CollectionField","x-decorator":"FormItem"},enabled:{"x-component":"CollectionField","x-decorator":"FormItem"},options:{type:"object","x-component":"Options"},footer:{type:"void","x-component":"Action.Drawer.Footer",properties:{cancel:{title:'{{t("Cancel")}}',"x-component":"Action","x-component-props":{useAction:"{{ cm.useCancelAction }}"}},submit:{title:'{{t("Submit")}}',"x-component":"Action","x-component-props":{type:"primary",useAction:"{{ cm.useCreateAction }}"}}}}}}}},U={type:"void",name:"authenticators","x-decorator":"ResourceActionProvider","x-decorator-props":{collection:F,resourceName:"authenticators",dragSort:!0,request:{resource:"authenticators",action:"list",params:{pageSize:50,sort:"sort",appends:[]}}},"x-component":"CollectionProvider","x-component-props":{collection:F},properties:{actions:{type:"void","x-component":"ActionBar","x-component-props":{style:{marginBottom:16}},properties:{delete:{type:"void",title:'{{t("Delete")}}',"x-component":"Action","x-component-props":{useAction:"{{ cm.useBulkDestroyAction }}",confirm:{title:"{{t('Delete')}}",content:"{{t('Are you sure you want to delete it?')}}"}}},create:{type:"void",title:'{{t("Add new")}}',"x-component":"AddNew","x-component-props":{type:"primary"}}}},table:{type:"void","x-uid":"input","x-component":"Table.Void","x-component-props":{rowKey:"id",rowSelection:{type:"checkbox"},useDataSource:"{{ cm.useDataSourceFromRAC }}",useAction(){const o=e.useAPIClient(),{t:r}=x.useTranslation();return{move(p,s){return f(this,null,function*(){yield o.resource("authenticators").move({sourceId:p.id,targetId:s.id}),l.message.success(r("Saved successfully"),.2)})}}}},properties:{id:{type:"void","x-decorator":"Table.Column.Decorator","x-component":"Table.Column",properties:{id:{type:"number","x-component":"CollectionField","x-read-pretty":!0}}},name:{type:"void","x-decorator":"Table.Column.Decorator","x-component":"Table.Column",properties:{name:{type:"string","x-component":"CollectionField","x-read-pretty":!0}}},authType:{title:'{{t("Auth Type")}}',type:"void","x-decorator":"Table.Column.Decorator","x-component":"Table.Column",properties:{authType:{type:"string","x-component":"Select","x-read-pretty":!0,enum:"{{ types }}"}}},title:{type:"void","x-decorator":"Table.Column.Decorator","x-component":"Table.Column",properties:{title:{type:"string","x-component":"CollectionField","x-read-pretty":!0}}},description:{type:"void","x-decorator":"Table.Column.Decorator","x-component":"Table.Column",properties:{description:{type:"boolean","x-component":"CollectionField","x-read-pretty":!0}}},enabled:{type:"void","x-decorator":"Table.Column.Decorator","x-component":"Table.Column",properties:{enabled:{type:"boolean","x-component":"CollectionField","x-read-pretty":!0}}},actions:{type:"void",title:'{{t("Actions")}}',"x-component":"Table.Column",properties:{actions:{type:"void","x-component":"Space","x-component-props":{split:"|"},properties:{update:{type:"void",title:'{{t("Configure")}}',"x-component":"Action.Link","x-component-props":{type:"primary"},properties:{drawer:{type:"void","x-component":"Action.Drawer","x-decorator":"Form","x-decorator-props":{useValues:"{{ cm.useValuesFromRecord }}"},title:'{{t("Configure")}}',properties:{name:{"x-component":"CollectionField","x-decorator":"FormItem"},authType:{"x-component":"CollectionField","x-decorator":"FormItem","x-component-props":{options:"{{ types }}"}},title:{"x-component":"CollectionField","x-decorator":"FormItem"},description:{"x-component":"CollectionField","x-decorator":"FormItem"},enabled:{"x-component":"CollectionField","x-decorator":"FormItem"},options:{type:"object","x-component":"Options"},footer:{type:"void","x-component":"Action.Drawer.Footer",properties:{cancel:{title:'{{t("Cancel")}}',"x-component":"Action","x-component-props":{useAction:"{{ cm.useCancelAction }}"}},submit:{title:'{{t("Submit")}}',"x-component":"Action","x-component-props":{type:"primary",useAction:"{{ cm.useUpdateAction }}"}}}}}}}},delete:{type:"void",title:'{{ t("Delete") }}',"x-component":"Action.Link","x-component-props":{confirm:{title:"{{t('Delete record')}}",content:"{{t('Are you sure you want to delete it?')}}"},useAction:"{{cm.useDestroyAction}}"},"x-disabled":"{{ useCanNotDelete() }}"}}}}}}}}},_=o=>{const r=e.useRecord(),i=e.useRequest(()=>Promise.resolve({data:g({},r.options)}),C(g({},o),{manual:!0})),{run:p}=i,s=e.useActionContext();return c.useEffect(()=>{s.visible&&p()},[s.visible,p]),i},N=d.observer(()=>{const o=d.useForm(),r=e.useRecord();return e.useOptionsComponent(o.values.authType||r.authType)}),M=()=>{const{setVisible:o}=e.useActionContext();return{run(){return f(this,null,function*(){o(!1)})}}},z=()=>{const{t:o}=x.useTranslation(),[r,i]=c.useState(!1),[p,s]=c.useState(""),u=V(),v=u.map(m=>C(g({},m),{onClick:()=>{i(!0),s(m.value)}}));return t.jsx(e.ActionContextProvider,{value:{visible:r,setVisible:i},children:t.jsxs(w.Provider,{value:{type:p},children:[t.jsx(l.Dropdown,{menu:{items:v},children:t.jsxs(l.Button,{icon:t.jsx(a.PlusOutlined,{}),type:"primary",children:[o("Add new")," ",t.jsx(a.DownOutlined,{})]})}),t.jsx(e.SchemaComponent,{scope:{useCloseAction:M,types:u,setType:s},schema:B})]})})},Z=()=>(e.useAsyncData(),!1),K=()=>{const{t:o}=h(),[r,i]=c.useState([]),p=e.useAPIClient();return e.useRequest(()=>p.resource("authenticators").listTypes().then(s=>{var v;return(((v=s==null?void 0:s.data)==null?void 0:v.data)||[]).map(m=>({key:m.name,label:o(m.title||m.name),value:m.name}))}),{onSuccess:s=>{i(s)}}),t.jsx(l.Card,{bordered:!1,children:t.jsx(T.Provider,{value:{types:r},children:t.jsx(e.SchemaComponent,{schema:U,components:{AddNew:z,Options:N},scope:{types:r,useValuesFromOptions:_,useCanNotDelete:Z,t:o}})})})};class P extends e.Plugin{load(){return f(this,null,function*(){this.app.pluginSettingsManager.add(S,{icon:"LoginOutlined",title:`{{t("Authentication", { ns: "${S}" })}}`,Component:K,aclSnippet:"pm.auth.authenticators"}),this.app.providers.unshift([E,{}]),this.app.use(L)})}}n.AuthPlugin=P,n.default=P,Object.defineProperties(n,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})});
|
|
22
|
+
}}}`,"x-decorator":"FormItem","x-component-props":{placeholder:'{{t("Username/Email")}}',style:{}}},password:{type:"string","x-component":"Password",required:!0,"x-decorator":"FormItem","x-component-props":{placeholder:'{{t("Password")}}',style:{}}},actions:{type:"void","x-component":"div",properties:{submit:{title:'{{t("Sign in")}}',type:"void","x-component":"Action","x-component-props":{htmlType:"submit",block:!0,type:"primary",useAction:"{{ useBasicSignIn }}",style:{width:"100%"}}}}},signUp:{type:"void","x-component":"Link","x-component-props":{to:"{{ signUpLink }}"},"x-content":'{{t("Create an account")}}',"x-visible":"{{ allowSignUp }}"}}},te=t=>{const{t:r}=A(),o=t.authenticator,{authType:i,name:s,options:a}=o,l=!!q()[i]&&(a==null?void 0:a.allowSignUp),ie=`/signup?name=${s}`,ce=()=>D(s);return n.jsx(e.SchemaComponent,{schema:ee,scope:{useBasicSignIn:ce,allowSignUp:l,signUpLink:ie,t:r}})},oe=t=>{const r=m.useNavigate(),o=h.useForm(),i=e.useAPIClient(),{t:s}=x.useTranslation();return{run(){return C(this,null,function*(){var p;yield o.submit(),yield i.auth.signUp(o.values,t==null?void 0:t.authenticator),d.message.success(((p=t==null?void 0:t.message)==null?void 0:p.success)||s("Sign up successfully, and automatically jump to the sign in page")),setTimeout(()=>{r("/signin")},2e3)})}}},ne={type:"object",name:g.uid(),"x-component":"FormV2",properties:{username:{type:"string",required:!0,"x-component":"Input","x-validator":{username:!0},"x-decorator":"FormItem","x-component-props":{placeholder:'{{t("Username")}}',style:{}}},password:{type:"string",required:!0,"x-component":"Password","x-decorator":"FormItem","x-component-props":{placeholder:'{{t("Password")}}',checkStrength:!0,style:{}},"x-reactions":[{dependencies:[".confirm_password"],fulfill:{state:{selfErrors:'{{$deps[0] && $self.value && $self.value !== $deps[0] ? t("Password mismatch") : ""}}'}}}]},confirm_password:{type:"string",required:!0,"x-component":"Password","x-decorator":"FormItem","x-component-props":{placeholder:'{{t("Confirm password")}}',style:{}},"x-reactions":[{dependencies:[".password"],fulfill:{state:{selfErrors:'{{$deps[0] && $self.value && $self.value !== $deps[0] ? t("Password mismatch") : ""}}'}}}]},actions:{type:"void","x-component":"div",properties:{submit:{title:'{{t("Sign up")}}',type:"void","x-component":"Action","x-component-props":{block:!0,type:"primary",htmlType:"submit",useAction:"{{ useBasicSignUp }}",style:{width:"100%"}}}}},link:{type:"void","x-component":"div",properties:{link:{type:"void","x-component":"Link","x-component-props":{to:"/signin"},"x-content":'{{t("Log in with an existing account")}}'}}}}},se=({authenticatorName:t})=>{const{t:r}=A(),o=()=>oe({authenticator:t}),i=w(t),{options:s}=i;return s!=null&&s.allowSignUp?n.jsx(e.SchemaComponent,{schema:ne,scope:{useBasicSignUp:o,t:r}}):n.jsx(m.Navigate,{to:"/not-found",replace:!0})},re=()=>{const{t}=A();return n.jsx(e.SchemaComponent,{scope:{t},components:{Alert:d.Alert},schema:{type:"object",properties:{public:{type:"object",properties:{allowSignUp:{"x-decorator":"FormItem",type:"boolean",title:'{{t("Allow to sign up")}}',"x-component":"Checkbox","x-component-props":{defaultChecked:!0}}}},notice:{type:"void","x-component":"Alert","x-component-props":{showIcon:!0,message:'{{t("The authentication allows users to sign in via username or email.")}}'}}}}})};class f extends e.Plugin{constructor(){super(...arguments);N(this,"authTypes",new E.Registry)}registerType(o,i){this.authTypes.register(o,i)}load(){return C(this,null,function*(){this.app.pluginSettingsManager.add(F,{icon:"LoginOutlined",title:`{{t("Authentication", { ns: "${F}" })}}`,Component:W,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:G,SignInPage:Q,SignUpPage:X}),this.app.providers.unshift([j,{}]),this.registerType(Y,{components:{SignInForm:te,SignUpForm:se,AdminSettingsForm:re}})})}}c.AuthPlugin=f,c.AuthenticatorsContext=S,c.default=f,c.useAuthenticator=w,c.useSignIn=D,Object.defineProperties(c,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})});
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { AuthOptions } from '..';
|
|
3
|
+
import { Authenticator } from '../authenticator';
|
|
4
|
+
export declare const useSignInForms: () => {
|
|
5
|
+
[authType: string]: React.ComponentType<{
|
|
6
|
+
authenticator: Authenticator;
|
|
7
|
+
}>;
|
|
8
|
+
};
|
|
9
|
+
export declare const useSignInButtons: (authenticators?: any[]) => React.CElement<{
|
|
10
|
+
key: number;
|
|
11
|
+
authenticator: any;
|
|
12
|
+
}, React.Component<{
|
|
13
|
+
key: number;
|
|
14
|
+
authenticator: any;
|
|
15
|
+
}, any, any>>[];
|
|
16
|
+
export declare const SignInPage: () => React.JSX.Element;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import React, { FunctionComponent } from 'react';
|
|
2
|
+
import { AuthOptions } from '..';
|
|
3
|
+
export declare const SignupPageContext: React.Context<{
|
|
4
|
+
[authType: string]: {
|
|
5
|
+
component: FunctionComponent<{
|
|
6
|
+
name: string;
|
|
7
|
+
}>;
|
|
8
|
+
};
|
|
9
|
+
}>;
|
|
10
|
+
export declare const SignupPageProvider: React.FC<{
|
|
11
|
+
authType: string;
|
|
12
|
+
component: FunctionComponent<{
|
|
13
|
+
name: string;
|
|
14
|
+
}>;
|
|
15
|
+
}>;
|
|
16
|
+
export declare const useSignUpForms: () => {
|
|
17
|
+
[authType: string]: React.ComponentType<{
|
|
18
|
+
authenticatorName: string;
|
|
19
|
+
}>;
|
|
20
|
+
};
|
|
21
|
+
export declare const SignUpPage: () => React.JSX.Element;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
|
|
1
|
+
import React from 'react';
|
|
2
2
|
export declare const useValuesFromOptions: (options: any) => {
|
|
3
3
|
state: {};
|
|
4
4
|
setState: import("ahooks/lib/useSetState").SetState<{}>;
|
|
@@ -13,4 +13,5 @@ export declare const useValuesFromOptions: (options: any) => {
|
|
|
13
13
|
runAsync: (...params: any) => Promise<unknown>;
|
|
14
14
|
mutate: (data?: unknown) => void;
|
|
15
15
|
};
|
|
16
|
-
export declare const
|
|
16
|
+
export declare const useAdminSettingsForm: (authType: string) => any;
|
|
17
|
+
export declare const Options: React.MemoExoticComponent<import("@formily/react").ReactFC<unknown>>;
|
package/dist/externalVersion.js
CHANGED
|
@@ -1,16 +1,18 @@
|
|
|
1
1
|
module.exports = {
|
|
2
|
-
"@nocobase/client": "0.
|
|
2
|
+
"@nocobase/client": "0.18.0-alpha.1",
|
|
3
3
|
"react": "18.2.0",
|
|
4
|
-
"react-router-dom": "6.
|
|
5
|
-
"@nocobase/
|
|
6
|
-
"@nocobase/
|
|
7
|
-
"@nocobase/
|
|
8
|
-
"@nocobase/
|
|
9
|
-
"@nocobase/
|
|
10
|
-
"
|
|
11
|
-
"
|
|
12
|
-
"@formily/
|
|
4
|
+
"react-router-dom": "6.21.0",
|
|
5
|
+
"@nocobase/utils": "0.18.0-alpha.1",
|
|
6
|
+
"@nocobase/auth": "0.18.0-alpha.1",
|
|
7
|
+
"@nocobase/database": "0.18.0-alpha.1",
|
|
8
|
+
"@nocobase/server": "0.18.0-alpha.1",
|
|
9
|
+
"@nocobase/cache": "0.18.0-alpha.1",
|
|
10
|
+
"@nocobase/test": "0.18.0-alpha.1",
|
|
11
|
+
"antd": "5.12.2",
|
|
12
|
+
"@formily/react": "2.3.0",
|
|
13
|
+
"@formily/shared": "2.3.0",
|
|
13
14
|
"react-i18next": "11.18.6",
|
|
14
|
-
"@
|
|
15
|
-
"@
|
|
15
|
+
"@emotion/css": "11.11.2",
|
|
16
|
+
"@ant-design/icons": "5.2.6",
|
|
17
|
+
"@nocobase/actions": "0.18.0-alpha.1"
|
|
16
18
|
};
|
package/dist/locale/en-US.json
CHANGED
|
@@ -19,5 +19,8 @@
|
|
|
19
19
|
"SMS": "SMS",
|
|
20
20
|
"Username/Email": "Username/Email",
|
|
21
21
|
"Auth UID": "Auth UID",
|
|
22
|
-
"The authentication allows users to sign in via username or email.": "The authentication allows users to sign in via username or email."
|
|
22
|
+
"The authentication allows users to sign in via username or email.": "The authentication allows users to sign in via username or email.",
|
|
23
|
+
"No authentication methods available.": "No authentication methods available.",
|
|
24
|
+
"The password is inconsistent, please re-enter": "The password is inconsistent, please re-enter",
|
|
25
|
+
"Sign-in": "Sign-in"
|
|
23
26
|
}
|
package/dist/locale/zh-CN.json
CHANGED
|
@@ -19,5 +19,8 @@
|
|
|
19
19
|
"SMS": "短信",
|
|
20
20
|
"Username/Email": "用户名/邮箱",
|
|
21
21
|
"Auth UID": "认证标识",
|
|
22
|
-
"The authentication allows users to sign in via username or email.": "该认证方式支持用户通过用户名或邮箱登录。"
|
|
22
|
+
"The authentication allows users to sign in via username or email.": "该认证方式支持用户通过用户名或邮箱登录。",
|
|
23
|
+
"No authentication methods available.": "没有可用的认证方式。",
|
|
24
|
+
"The password is inconsistent, please re-enter": "密码不一致,请重新输入",
|
|
25
|
+
"Sign-in": "登录"
|
|
23
26
|
}
|
|
File without changes
|