@nocobase/plugin-auth-sms 1.7.0-alpha.1 → 1.7.0-beta.2

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.
@@ -0,0 +1,15 @@
1
+ /**
2
+ * This file is part of the NocoBase (R) project.
3
+ * Copyright (c) 2020-2024 NocoBase Co., Ltd.
4
+ * Authors: NocoBase Team.
5
+ *
6
+ * This project is dual-licensed under AGPL-3.0 and NocoBase Commercial License.
7
+ * For more information, please refer to: https://www.nocobase.com/agreement.
8
+ */
9
+ import React from 'react';
10
+ export default function VerificationCode({ targetFieldName, actionType, value, onChange }: {
11
+ targetFieldName?: string;
12
+ actionType: any;
13
+ value: any;
14
+ onChange: any;
15
+ }): React.JSX.Element;
@@ -7,4 +7,4 @@
7
7
  * For more information, please refer to: https://www.nocobase.com/agreement.
8
8
  */
9
9
 
10
- !function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t(require("react-i18next"),require("@nocobase/plugin-auth/client"),require("@formily/react"),require("@nocobase/plugin-verification/client"),require("@nocobase/client"),require("react")):"function"==typeof define&&define.amd?define("@nocobase/plugin-auth-sms",["react-i18next","@nocobase/plugin-auth/client","@formily/react","@nocobase/plugin-verification/client","@nocobase/client","react"],t):"object"==typeof exports?exports["@nocobase/plugin-auth-sms"]=t(require("react-i18next"),require("@nocobase/plugin-auth/client"),require("@formily/react"),require("@nocobase/plugin-verification/client"),require("@nocobase/client"),require("react")):e["@nocobase/plugin-auth-sms"]=t(e["react-i18next"],e["@nocobase/plugin-auth/client"],e["@formily/react"],e["@nocobase/plugin-verification/client"],e["@nocobase/client"],e.react)}(self,function(e,t,n,r,o,i){return function(){"use strict";var u={505:function(e){e.exports=n},772:function(e){e.exports=o},689:function(e){e.exports=t},697:function(e){e.exports=r},156:function(e){e.exports=i},238:function(t){t.exports=e}},c={};function a(e){var t=c[e];if(void 0!==t)return t.exports;var n=c[e]={exports:{}};return u[e](n,n.exports,a),n.exports}a.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return a.d(t,{a:t}),t},a.d=function(e,t){for(var n in t)a.o(t,n)&&!a.o(e,n)&&Object.defineProperty(e,n,{enumerable:!0,get:t[n]})},a.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},a.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})};var l={};a.r(l),a.d(l,{PluginAuthSMSClient:function(){return C},default:function(){return E}});var s=a("772"),p=a("689"),f=a.n(p),y=a("505"),b=a("156"),v=a.n(b),m=a("697"),h=a("238");function d(){return(0,h.useTranslation)(["auth-sms","client"],{nsMode:"fallback"})}function g(e,t,n,r,o,i,u){try{var c=e[i](u),a=c.value}catch(e){n(e);return}c.done?t(a):Promise.resolve(a).then(r,o)}var x={type:"object",name:"phoneForm","x-component":"FormV2",properties:{form:{type:"void","x-component":"VerificationForm","x-component-props":{actionType:"auth:signIn",verificator:"{{ verificator }}"}},actions:{type:"void",title:'{{t("Sign in")}}',"x-component":"Action","x-use-component-props":"useVerifyActionProps","x-component-props":{htmlType:"submit",block:!0,type:"primary",style:{width:"100%"}}},tip:{type:"void","x-component":"div","x-content":'{{t("User will be registered automatically if not exists.", {ns: "auth-sms"})}}',"x-component-props":{style:{color:"#ccc"}},"x-visible":"{{ autoSignup }}"}}},S=function(e){var t=(0,y.useForm)(),n=(0,s.useAPIClient)(),r=(0,p.useRedirect)(),o=(0,s.useCurrentUserContext)().refreshAsync;return{title:(0,d().t)("Sign in"),onClick:function(){var i;return(i=function(){return function(e,t){var n,r,o,i,u={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return i={next:c(0),throw:c(1),return:c(2)},"function"==typeof Symbol&&(i[Symbol.iterator]=function(){return this}),i;function c(i){return function(c){return function(i){if(n)throw TypeError("Generator is already executing.");for(;u;)try{if(n=1,r&&(o=2&i[0]?r.return:i[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,i[1])).done)return o;switch(r=0,o&&(i=[2&i[0],o.value]),i[0]){case 0:case 1:o=i;break;case 4:return u.label++,{value:i[1],done:!1};case 5:u.label++,r=i[1],i=[0];continue;case 7:i=u.ops.pop(),u.trys.pop();continue;default:if(!(o=(o=u.trys).length>0&&o[o.length-1])&&(6===i[0]||2===i[0])){u=0;continue}if(3===i[0]&&(!o||i[1]>o[0]&&i[1]<o[3])){u.label=i[1];break}if(6===i[0]&&u.label<o[1]){u.label=o[1],o=i;break}if(o&&u.label<o[2]){u.label=o[2],u.ops.push(i);break}o[2]&&u.ops.pop(),u.trys.pop();continue}i=t.call(e,u)}catch(e){i=[6,e],r=0}finally{n=o=0}if(5&i[0])throw i[1];return{value:i[0]?i[1]:void 0,done:!0}}([i,c])}}}(this,function(i){switch(i.label){case 0:return[4,t.submit()];case 1:return i.sent(),[4,n.auth.signIn(t.values,e)];case 2:return i.sent(),[4,o()];case 3:return i.sent(),r(),[2]}})},function(){var e=this,t=arguments;return new Promise(function(n,r){var o=i.apply(e,t);function u(e){g(o,n,r,u,c,"next",e)}function c(e){g(o,n,r,u,c,"throw",e)}u(void 0)})})()}}},w=function(e){var t=e.authenticator,n=t.name,r=t.options,o=!!(null==r?void 0:r.autoSignup),i=(0,s.usePlugin)("verification").verificationManager.getVerification(m.SMS_OTP_VERIFICATION_TYPE),u=null==i?void 0:i.components.VerificationForm;return v().createElement(s.SchemaComponent,{schema:x,scope:{useVerifyActionProps:function(){return S(n)},autoSignup:o,verificator:null==r?void 0:r.verificator},components:{VerificationForm:u}})},P=function(){var e=d().t;return v().createElement(s.SchemaComponent,{scope:{t:e},schema:{type:"object",properties:{sms:{type:"void",properties:{public:{type:"object",properties:{verificator:{type:"string","x-component":"VerificatorSelect","x-component-props":{title:'{{t("Verificator")}}',scene:"auth-sms"}},autoSignup:{"x-decorator":"FormItem",type:"boolean",title:'{{t("Sign up automatically when the user does not exist")}}',"x-component":"Checkbox"}}}}}}}})};function O(e,t,n,r,o,i,u){try{var c=e[i](u),a=c.value}catch(e){n(e);return}c.done?t(a):Promise.resolve(a).then(r,o)}function j(e,t,n){return(j=F()?Reflect.construct:function(e,t,n){var r=[null];r.push.apply(r,t);var o=new(Function.bind.apply(e,r));return n&&T(o,n.prototype),o}).apply(null,arguments)}function _(e,t){for(var n=0;n<t.length;n++){var r=t[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(e,r.key,r)}}function k(e){return(k=Object.setPrototypeOf?Object.getPrototypeOf:function(e){return e.__proto__||Object.getPrototypeOf(e)})(e)}function T(e,t){return(T=Object.setPrototypeOf||function(e,t){return e.__proto__=t,e})(e,t)}function q(e){var t="function"==typeof Map?new Map:void 0;return(q=function(e){var n;if(null===e||(n=e,-1===Function.toString.call(n).indexOf("[native code]")))return e;if("function"!=typeof e)throw TypeError("Super expression must either be null or a function");if(void 0!==t){if(t.has(e))return t.get(e);t.set(e,r)}function r(){return j(e,arguments,k(this).constructor)}return r.prototype=Object.create(e.prototype,{constructor:{value:r,enumerable:!1,writable:!0,configurable:!0}}),T(r,e)})(e)}function F(){try{var e=!Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){}))}catch(e){}return(F=function(){return!!e})()}var C=function(e){var t,n,r;function o(){var e,t,n;return!function(e,t){if(!(e instanceof t))throw TypeError("Cannot call a class as a function")}(this,o),e=this,t=o,n=arguments,t=k(t),function(e,t){return t&&("object"===function(e){return e&&"undefined"!=typeof Symbol&&e.constructor===Symbol?"symbol":typeof e}(t)||"function"==typeof t)?t:function(e){if(void 0===e)throw ReferenceError("this hasn't been initialised - super() hasn't been called");return e}(e)}(e,F()?Reflect.construct(t,n||[],k(e).constructor):t.apply(e,n))}return!function(e,t){if("function"!=typeof t&&null!==t)throw TypeError("Super expression must either be null or a function");e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,writable:!0,configurable:!0}}),t&&T(e,t)}(o,e),t=o,n=[{key:"load",value:function(){var e,t=this;return(e=function(){return function(e,t){var n,r,o,i,u={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return i={next:c(0),throw:c(1),return:c(2)},"function"==typeof Symbol&&(i[Symbol.iterator]=function(){return this}),i;function c(i){return function(c){return function(i){if(n)throw TypeError("Generator is already executing.");for(;u;)try{if(n=1,r&&(o=2&i[0]?r.return:i[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,i[1])).done)return o;switch(r=0,o&&(i=[2&i[0],o.value]),i[0]){case 0:case 1:o=i;break;case 4:return u.label++,{value:i[1],done:!1};case 5:u.label++,r=i[1],i=[0];continue;case 7:i=u.ops.pop(),u.trys.pop();continue;default:if(!(o=(o=u.trys).length>0&&o[o.length-1])&&(6===i[0]||2===i[0])){u=0;continue}if(3===i[0]&&(!o||i[1]>o[0]&&i[1]<o[3])){u.label=i[1];break}if(6===i[0]&&u.label<o[1]){u.label=o[1],o=i;break}if(o&&u.label<o[2]){u.label=o[2],u.ops.push(i);break}o[2]&&u.ops.pop(),u.trys.pop();continue}i=t.call(e,u)}catch(e){i=[6,e],r=0}finally{n=o=0}if(5&i[0])throw i[1];return{value:i[0]?i[1]:void 0,done:!0}}([i,c])}}}(this,function(e){return t.app.pm.get(f()).registerType("SMS",{components:{SignInForm:w,AdminSettingsForm:P}}),[2]})},function(){var t=this,n=arguments;return new Promise(function(r,o){var i=e.apply(t,n);function u(e){O(i,r,o,u,c,"next",e)}function c(e){O(i,r,o,u,c,"throw",e)}u(void 0)})})()}}],_(t.prototype,n),o}(q(s.Plugin)),E=C;return l}()});
10
+ !function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t(require("react-i18next"),require("@nocobase/plugin-auth/client"),require("@formily/react"),require("@nocobase/client"),require("react"),require("antd")):"function"==typeof define&&define.amd?define("@nocobase/plugin-auth-sms",["react-i18next","@nocobase/plugin-auth/client","@formily/react","@nocobase/client","react","antd"],t):"object"==typeof exports?exports["@nocobase/plugin-auth-sms"]=t(require("react-i18next"),require("@nocobase/plugin-auth/client"),require("@formily/react"),require("@nocobase/client"),require("react"),require("antd")):e["@nocobase/plugin-auth-sms"]=t(e["react-i18next"],e["@nocobase/plugin-auth/client"],e["@formily/react"],e["@nocobase/client"],e.react,e.antd)}(self,function(e,t,n,r,o,i){return function(){"use strict";var u={505:function(e){e.exports=n},772:function(e){e.exports=r},689:function(e){e.exports=t},721:function(e){e.exports=i},156:function(e){e.exports=o},238:function(t){t.exports=e}},c={};function a(e){var t=c[e];if(void 0!==t)return t.exports;var n=c[e]={exports:{}};return u[e](n,n.exports,a),n.exports}a.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return a.d(t,{a:t}),t},a.d=function(e,t){for(var n in t)a.o(t,n)&&!a.o(e,n)&&Object.defineProperty(e,n,{enumerable:!0,get:t[n]})},a.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},a.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})};var l={};a.r(l),a.d(l,{PluginAuthSMSClient:function(){return C},default:function(){return F}});var s=a("772"),p=a("689"),f=a.n(p),y=a("156"),b=a.n(y),d=a("505"),h=a("721"),m=a("238");function v(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=Array(t);n<t;n++)r[n]=e[n];return r}function g(e,t,n,r,o,i,u){try{var c=e[i](u),a=c.value}catch(e){n(e);return}c.done?t(a):Promise.resolve(a).then(r,o)}function x(){var e,t,n=(e=["\n display: flex;\n gap: 0.5em;\n "],!t&&(t=e.slice(0)),Object.freeze(Object.defineProperties(e,{raw:{value:Object.freeze(t)}})));return x=function(){return n},n}function S(e){var t,n,r=e.targetFieldName,o=void 0===r?"phone":r,i=e.actionType,u=e.value,c=e.onChange,a=(0,m.useTranslation)().t,l=(0,s.useAPIClient)(),p=(0,d.useForm)();var f=(t=(0,y.useState)(0),n=2,function(e){if(Array.isArray(e))return e}(t)||function(e,t){var n,r,o=null==e?null:"undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(null!=o){var i=[],u=!0,c=!1;try{for(o=o.call(e);!(u=(n=o.next()).done)&&(i.push(n.value),!t||i.length!==t);u=!0);}catch(e){c=!0,r=e}finally{try{!u&&null!=o.return&&o.return()}finally{if(c)throw r}}return i}}(t,2)||function(e,t){if(e){if("string"==typeof e)return v(e,t);var n=Object.prototype.toString.call(e).slice(8,-1);if("Object"===n&&e.constructor&&(n=e.constructor.name),"Map"===n||"Set"===n)return Array.from(n);if("Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n))return v(e,t)}}(t,n)||function(){throw TypeError("Invalid attempt to destructure non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()),S=f[0],w=f[1],j=(0,y.useRef)(null);(0,y.useEffect)(function(){S<=0&&j.current&&clearInterval(j.current)},[S]);function O(){var e;return e=function(){var e;return function(e,t){var n,r,o,i,u={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return i={next:c(0),throw:c(1),return:c(2)},"function"==typeof Symbol&&(i[Symbol.iterator]=function(){return this}),i;function c(i){return function(c){return function(i){if(n)throw TypeError("Generator is already executing.");for(;u;)try{if(n=1,r&&(o=2&i[0]?r.return:i[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,i[1])).done)return o;switch(r=0,o&&(i=[2&i[0],o.value]),i[0]){case 0:case 1:o=i;break;case 4:return u.label++,{value:i[1],done:!1};case 5:u.label++,r=i[1],i=[0];continue;case 7:i=u.ops.pop(),u.trys.pop();continue;default:if(!(o=(o=u.trys).length>0&&o[o.length-1])&&(6===i[0]||2===i[0])){u=0;continue}if(3===i[0]&&(!o||i[1]>o[0]&&i[1]<o[3])){u.label=i[1];break}if(6===i[0]&&u.label<o[1]){u.label=o[1],o=i;break}if(o&&u.label<o[2]){u.label=o[2],u.ops.push(i);break}o[2]&&u.ops.pop(),u.trys.pop();continue}i=t.call(e,u)}catch(e){i=[6,e],r=0}finally{n=o=0}if(5&i[0])throw i[1];return{value:i[0]?i[1]:void 0,done:!0}}([i,c])}}}(this,function(t){switch(t.label){case 0:if(S>0)return[2];t.label=1;case 1:return t.trys.push([1,3,,4]),[4,l.resource("verifications").create({values:{type:i,phone:p.values[o]}})];case 2:return e=t.sent().data.data,h.message.success(a("Operation succeeded")),u&&c(""),w(e.expiresAt?Math.ceil((Date.parse(e.expiresAt)-Date.now())/1e3):60),j.current=setInterval(function(){w(function(e){return e-1})},1e3),[3,4];case 3:return console.error(t.sent()),[3,4];case 4:return[2]}})},(O=function(){var t=this,n=arguments;return new Promise(function(r,o){var i=e.apply(t,n);function u(e){g(i,r,o,u,c,"next",e)}function c(e){g(i,r,o,u,c,"throw",e)}u(void 0)})}).apply(this,arguments)}return b().createElement("fieldset",{className:(0,s.css)(x())},b().createElement(h.Input,{value:u,onChange:c,placeholder:a("Verification code")}),b().createElement(h.Button,{onClick:function(){return O.apply(this,arguments)},disabled:S>0},S>0?a("Retry after {{count}} seconds",{count:S}):a("Send code")))}var w={type:"object",name:"phoneForm","x-component":"Form",properties:{phone:{type:"string",required:!0,"x-component":"Input","x-validator":"phone","x-decorator":"FormItem","x-component-props":{placeholder:'{{t("Phone")}}',style:{}}},code:{type:"string",required:!0,"x-component":"VerificationCode","x-component-props":{actionType:"auth:signIn",targetFieldName:"phone"},"x-decorator":"FormItem"},actions:{title:'{{t("Sign in")}}',type:"void","x-component":"Action","x-component-props":{htmlType:"submit",block:!0,type:"primary",useAction:"{{ useSMSSignIn }}",style:{width:"100%"}}},tip:{type:"void","x-component":"div","x-content":'{{t("User will be registered automatically if not exists.", {ns: "auth-sms"})}}',"x-component-props":{style:{color:"#ccc"}},"x-visible":"{{ autoSignup }}"}}},j=function(e){var t=e.authenticator,n=t.name,r=t.options,o=!!(null==r?void 0:r.autoSignup);return b().createElement(s.SchemaComponent,{schema:w,scope:{useSMSSignIn:function(){return(0,p.useSignIn)(n)},autoSignup:o},components:{VerificationCode:S}})},O=function(){var e=(0,m.useTranslation)("auth-sms").t;return b().createElement(s.SchemaComponent,{scope:{t:e},schema:{type:"object",properties:{sms:{type:"void",properties:{public:{type:"object",properties:{autoSignup:{"x-decorator":"FormItem",type:"boolean",title:'{{t("Sign up automatically when the user does not exist")}}',"x-component":"Checkbox"}}}}}}}})};function P(e,t,n,r,o,i,u){try{var c=e[i](u),a=c.value}catch(e){n(e);return}c.done?t(a):Promise.resolve(a).then(r,o)}function I(e,t,n){return(I=E()?Reflect.construct:function(e,t,n){var r=[null];r.push.apply(r,t);var o=new(Function.bind.apply(e,r));return n&&k(o,n.prototype),o}).apply(null,arguments)}function q(e,t){for(var n=0;n<t.length;n++){var r=t[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(e,r.key,r)}}function T(e){return(T=Object.setPrototypeOf?Object.getPrototypeOf:function(e){return e.__proto__||Object.getPrototypeOf(e)})(e)}function k(e,t){return(k=Object.setPrototypeOf||function(e,t){return e.__proto__=t,e})(e,t)}function A(e){var t="function"==typeof Map?new Map:void 0;return(A=function(e){var n;if(null===e||(n=e,-1===Function.toString.call(n).indexOf("[native code]")))return e;if("function"!=typeof e)throw TypeError("Super expression must either be null or a function");if(void 0!==t){if(t.has(e))return t.get(e);t.set(e,r)}function r(){return I(e,arguments,T(this).constructor)}return r.prototype=Object.create(e.prototype,{constructor:{value:r,enumerable:!1,writable:!0,configurable:!0}}),k(r,e)})(e)}function E(){try{var e=!Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){}))}catch(e){}return(E=function(){return!!e})()}var C=function(e){var t,n,r;function o(){var e,t,n;return!function(e,t){if(!(e instanceof t))throw TypeError("Cannot call a class as a function")}(this,o),e=this,t=o,n=arguments,t=T(t),function(e,t){return t&&("object"===function(e){return e&&"undefined"!=typeof Symbol&&e.constructor===Symbol?"symbol":typeof e}(t)||"function"==typeof t)?t:function(e){if(void 0===e)throw ReferenceError("this hasn't been initialised - super() hasn't been called");return e}(e)}(e,E()?Reflect.construct(t,n||[],T(e).constructor):t.apply(e,n))}return!function(e,t){if("function"!=typeof t&&null!==t)throw TypeError("Super expression must either be null or a function");e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,writable:!0,configurable:!0}}),t&&k(e,t)}(o,e),t=o,n=[{key:"load",value:function(){var e,t=this;return(e=function(){return function(e,t){var n,r,o,i,u={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return i={next:c(0),throw:c(1),return:c(2)},"function"==typeof Symbol&&(i[Symbol.iterator]=function(){return this}),i;function c(i){return function(c){return function(i){if(n)throw TypeError("Generator is already executing.");for(;u;)try{if(n=1,r&&(o=2&i[0]?r.return:i[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,i[1])).done)return o;switch(r=0,o&&(i=[2&i[0],o.value]),i[0]){case 0:case 1:o=i;break;case 4:return u.label++,{value:i[1],done:!1};case 5:u.label++,r=i[1],i=[0];continue;case 7:i=u.ops.pop(),u.trys.pop();continue;default:if(!(o=(o=u.trys).length>0&&o[o.length-1])&&(6===i[0]||2===i[0])){u=0;continue}if(3===i[0]&&(!o||i[1]>o[0]&&i[1]<o[3])){u.label=i[1];break}if(6===i[0]&&u.label<o[1]){u.label=o[1],o=i;break}if(o&&u.label<o[2]){u.label=o[2],u.ops.push(i);break}o[2]&&u.ops.pop(),u.trys.pop();continue}i=t.call(e,u)}catch(e){i=[6,e],r=0}finally{n=o=0}if(5&i[0])throw i[1];return{value:i[0]?i[1]:void 0,done:!0}}([i,c])}}}(this,function(e){return t.app.pm.get(f()).registerType("SMS",{components:{SignInForm:j,AdminSettingsForm:O}}),[2]})},function(){var t=this,n=arguments;return new Promise(function(r,o){var i=e.apply(t,n);function u(e){P(i,r,o,u,c,"next",e)}function c(e){P(i,r,o,u,c,"throw",e)}u(void 0)})})()}}],q(t.prototype,n),o}(A(s.Plugin)),F=C;return l}()});
@@ -7,4 +7,4 @@
7
7
  * For more information, please refer to: https://www.nocobase.com/agreement.
8
8
  */
9
9
  export declare const NAMESPACE = "auth-sms";
10
- export declare function useAuthTranslation(): import("react-i18next").UseTranslationResponse<("auth-sms" | "client")[], undefined>;
10
+ export declare function useAuthTranslation(): import("react-i18next").UseTranslationResponse<"auth-sms", undefined>;
@@ -8,14 +8,15 @@
8
8
  */
9
9
 
10
10
  module.exports = {
11
- "@nocobase/client": "1.7.0-alpha.1",
11
+ "@nocobase/client": "1.7.0-beta.2",
12
12
  "react": "18.2.0",
13
13
  "@formily/react": "2.3.0",
14
- "@nocobase/plugin-auth": "1.7.0-alpha.1",
15
- "@nocobase/plugin-verification": "1.7.0-alpha.1",
16
- "@nocobase/server": "1.7.0-alpha.1",
17
- "@nocobase/utils": "1.7.0-alpha.1",
18
- "@nocobase/auth": "1.7.0-alpha.1",
19
- "@nocobase/database": "1.7.0-alpha.1",
20
- "react-i18next": "11.18.6"
14
+ "@nocobase/plugin-auth": "1.7.0-beta.2",
15
+ "antd": "5.12.8",
16
+ "react-i18next": "11.18.6",
17
+ "@nocobase/plugin-verification": "1.7.0-beta.2",
18
+ "@nocobase/server": "1.7.0-beta.2",
19
+ "@nocobase/utils": "1.7.0-beta.2",
20
+ "@nocobase/auth": "1.7.0-beta.2",
21
+ "@nocobase/database": "1.7.0-beta.2"
21
22
  };
@@ -0,0 +1,6 @@
1
+ {
2
+ "Sign in via SMS": "Anmeldung per SMS",
3
+ "User will be registered automatically if not exists.": "Benutzer wird automatisch registriert, wenn er nicht existiert.",
4
+ "Sign up automatically when the user does not exist": "Automatische Registrierung, wenn der Benutzer nicht existiert",
5
+ "SMS": "SMS"
6
+ }
@@ -2,6 +2,5 @@
2
2
  "Sign in via SMS": "Sign in via SMS",
3
3
  "User will be registered automatically if not exists.": "User will be registered automatically if not exists.",
4
4
  "Sign up automatically when the user does not exist": "Sign up automatically when the user does not exist",
5
- "SMS": "SMS",
6
- "Verificator": "Verificator"
5
+ "SMS": "SMS"
7
6
  }
@@ -0,0 +1,6 @@
1
+ {
2
+ "Sign in via SMS": "Sign in via SMS",
3
+ "User will be registered automatically if not exists.": "User will be registered automatically if not exists.",
4
+ "Sign up automatically when the user does not exist": "Sign up automatically when the user does not exist",
5
+ "SMS": "SMS"
6
+ }
@@ -2,6 +2,5 @@
2
2
  "Sign in via SMS": "短信登录",
3
3
  "User will be registered automatically if not exists.": "用户不存在时将自动注册。",
4
4
  "Sign up automatically when the user does not exist": "用户不存在时自动注册",
5
- "SMS": "短信",
6
- "Verificator": "验证器"
5
+ "SMS": "短信"
7
6
  }
@@ -0,0 +1,8 @@
1
+ {
2
+ "The email is incorrect, please re-enter": "The email is incorrect, please re-enter",
3
+ "Please fill in your email address": "Please fill in your email address",
4
+ "The password is incorrect, please re-enter": "The password is incorrect, please re-enter",
5
+ "Not a valid cellphone number, please re-enter": "Not a valid cellphone number, please re-enter",
6
+ "The phone number has been registered, please login directly": "The phone number has been registered, please login directly",
7
+ "The phone number is not registered, please register first": "The phone number is not registered, please register first"
8
+ }
@@ -43,10 +43,17 @@ class PluginAuthSMSServer extends import_server.Plugin {
43
43
  this.app.logger.warn("auth-sms: @nocobase/plugin-verification is required");
44
44
  return;
45
45
  }
46
- verificationPlugin.verificationManager.registerAction("auth:signIn", {
46
+ verificationPlugin.interceptors.register("auth:signIn", {
47
47
  manual: true,
48
- getBoundInfoFromCtx: (ctx) => {
49
- return ctx.action.params.values || {};
48
+ getReceiver: (ctx) => {
49
+ return ctx.action.params.values.phone;
50
+ },
51
+ expiresIn: 120,
52
+ validate: async (ctx, phone) => {
53
+ if (!phone) {
54
+ throw new Error(ctx.t("Not a valid cellphone number, please re-enter"));
55
+ }
56
+ return true;
50
57
  }
51
58
  });
52
59
  this.app.authManager.registerTypes(import_constants.authType, {
@@ -40,23 +40,16 @@ class SMSAuth extends import_auth.BaseAuth {
40
40
  });
41
41
  }
42
42
  async validate() {
43
- var _a;
44
43
  const ctx = this.ctx;
45
44
  const verificationPlugin = ctx.app.getPlugin("verification");
46
45
  if (!verificationPlugin) {
47
- ctx.log.error("auth-sms: @nocobase/plugin-verification is required", { method: "validate" });
48
- ctx.throw(500);
46
+ throw new Error("auth-sms: @nocobase/plugin-verification is required");
49
47
  }
50
48
  let user;
51
- ctx.action.mergeParams({
52
- values: {
53
- verificator: (_a = this.options.public) == null ? void 0 : _a.verificator
54
- }
55
- });
56
- await verificationPlugin.verificationManager.verify(ctx, async () => {
57
- var _a2;
49
+ await verificationPlugin.intercept(ctx, async () => {
50
+ var _a;
58
51
  const {
59
- values: { uuid: phone }
52
+ values: { phone }
60
53
  } = ctx.action.params;
61
54
  try {
62
55
  user = await this.userRepository.findOne({
@@ -70,7 +63,7 @@ class SMSAuth extends import_auth.BaseAuth {
70
63
  });
71
64
  return;
72
65
  }
73
- const { autoSignup } = ((_a2 = this.authenticator.options) == null ? void 0 : _a2.public) || {};
66
+ const { autoSignup } = ((_a = this.authenticator.options) == null ? void 0 : _a.public) || {};
74
67
  const authenticator = this.authenticator;
75
68
  if (autoSignup) {
76
69
  user = await authenticator.findOrCreateUser(phone, {
@@ -84,7 +77,7 @@ class SMSAuth extends import_auth.BaseAuth {
84
77
  throw new Error(ctx.t("The phone number is not registered, please register first", { ns: import_constants.namespace }));
85
78
  }
86
79
  } catch (err) {
87
- ctx.log.error(err, { method: "validate" });
80
+ console.log(err);
88
81
  throw new Error(err.message);
89
82
  }
90
83
  });
package/package.json CHANGED
@@ -4,7 +4,7 @@
4
4
  "displayName.zh-CN": "认证:短信",
5
5
  "description": "SMS authentication.",
6
6
  "description.zh-CN": "通过短信验证码认证身份。",
7
- "version": "1.7.0-alpha.1",
7
+ "version": "1.7.0-beta.2",
8
8
  "main": "./dist/server/index.js",
9
9
  "homepage": "https://docs.nocobase.com/handbook/auth-sms",
10
10
  "homepage.zh-CN": "https://docs-cn.nocobase.com/handbook/auth-sms",
@@ -25,7 +25,7 @@
25
25
  "@nocobase/server": "1.x",
26
26
  "@nocobase/test": "1.x"
27
27
  },
28
- "gitHead": "e411c9728b4d1f16b0beac16e40dd3499352b052",
28
+ "gitHead": "58b206bdfca521e79a69989ca55dd19075dca523",
29
29
  "keywords": [
30
30
  "Authentication"
31
31
  ]