UNPKG

@nocobase/plugin-auth

Version:

User authentication management, including password, SMS, and support for Single Sign-On (SSO) protocols, with extensibility.

10 lines (9 loc) 7.66 kB
/** * This file is part of the NocoBase (R) project. * Copyright (c) 2020-2024 NocoBase Co., Ltd. * Authors: NocoBase Team. * * This project is dual-licensed under AGPL-3.0 and NocoBase Commercial License. * For more information, please refer to: https://www.nocobase.com/agreement. */ "use strict";(self.webpackChunk_nocobase_plugin_auth=self.webpackChunk_nocobase_plugin_auth||[]).push([["257"],{852:function(e,t,n){n.r(t),n.d(t,{AuthLayout:function(){return p},SignInPage:function(){return w},SignUpPage:function(){return I},SignupPageContext:function(){return j},useSignInButtons:function(){return P},useSignUpForms:function(){return C},AuthenticatorsContextProvider:function(){return m},useSignInForms:function(){return T},SignupPageProvider:function(){return A}});var r=n(964),a=n(772),o=n(721),u=n(156),i=n.n(u),l=n(128),c=n(238),f=n(446);function s(){var e,t,n=(e=["\n position: absolute;\n bottom: 0;\n width: 100%;\n left: 0;\n text-align: center;\n padding-bottom: 24px;\n background-color: ",";\n "],t||(t=e.slice(0)),Object.freeze(Object.defineProperties(e,{raw:{value:Object.freeze(t)}})));return s=function(){return n},n}var m=function(e){var t=e.children,n=(0,a.useAPIClient)(),r=(0,a.useRequest)(function(){return n.resource("authenticators").publicList().then(function(e){var t;return(null==e||null==(t=e.data)?void 0:t.data)||[]})}),u=r.data,l=r.error;if(r.loading)return i().createElement("div",{style:{textAlign:"center",marginTop:20}},i().createElement(o.Spin,null));if(l)throw l;return i().createElement(f.H.Provider,{value:void 0===u?[]:u},t)};function p(){var e,t=((0,a.useSystemSettings)()||{}).data,n=(0,a.useToken)().token,o=(0,c.useTranslation)("lm-collections").t;return i().createElement("div",{style:{maxWidth:320,margin:"0 auto",paddingTop:"20vh",paddingBottom:"20vh"}},i().createElement("div",{style:{position:"fixed",top:"2em",right:"2em"}},i().createElement(a.SwitchLanguage,null)),i().createElement("h1",{style:{textAlign:"center"}},i().createElement(a.ReadPretty.TextArea,{value:o(null==t||null==(e=t.data)?void 0:e.title)})),i().createElement(m,null,i().createElement(l.Outlet,null)),i().createElement("div",{className:(0,r.css)(s(),n.colorBgContainer)},i().createElement(a.PoweredBy,null)))}var y=n(872),v=n(748),d=n(505);function g(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 h(e,t){return function(e){if(Array.isArray(e))return e}(e)||function(e,t){var n,r,a=null==e?null:"undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(null!=a){var o=[],u=!0,i=!1;try{for(a=a.call(e);!(u=(n=a.next()).done)&&(o.push(n.value),!t||o.length!==t);u=!0);}catch(e){i=!0,r=e}finally{try{u||null==a.return||a.return()}finally{if(i)throw r}}return o}}(e,t)||function(e,t){if(e){if("string"==typeof e)return g(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 g(e,t)}}(e,t)||function(){throw TypeError("Invalid attempt to destructure non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function b(e,t){return t||(t=e.slice(0)),Object.freeze(Object.defineProperties(e,{raw:{value:Object.freeze(t)}}))}function S(){var e=b(["\n display: flex;\n "]);return S=function(){return e},e}function E(){var e=b(["\n display: flex;\n "]);return E=function(){return e},e}var T=function(){var e=(0,a.usePlugin)(y.default).authTypes.getEntities(),t={},n=!0,r=!1,o=void 0;try{for(var u,i=e[Symbol.iterator]();!(n=(u=i.next()).done);n=!0){var l,c=h(u.value,2),f=c[0],s=c[1];(null==(l=s.components)?void 0:l.SignInForm)&&(t[f]=s.components.SignInForm)}}catch(e){r=!0,o=e}finally{try{n||null==i.return||i.return()}finally{if(r)throw o}}return t},P=function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:[],t=(0,a.usePlugin)(y.default).authTypes.getEntities(),n={},r=!0,o=!1,u=void 0;try{for(var l,c=t[Symbol.iterator]();!(r=(l=c.next()).done);r=!0){var f,s=h(l.value,2),m=s[0],p=s[1];(null==(f=p.components)?void 0:f.SignInButton)&&(n[m]=p.components.SignInButton)}}catch(e){o=!0,u=e}finally{try{r||null==c.return||c.return()}finally{if(o)throw u}}var v=Object.keys(n);return e.filter(function(e){return v.includes(e.authType)}).map(function(e,t){return i().createElement(n[e.authType],{key:t,authenticator:e})})},w=function(){var e=(0,v.o$)().t;(0,a.useCurrentDocumentTitle)("Signin"),(0,a.useViewport)();var t=T(),n=(0,u.useContext)(f.H),l=P(n);if(!n.length)return i().createElement("div",{style:{color:"#ccc"}},e("No authentication methods available."));var c=n.map(function(n){var r=t[n.authType];if(r){var a="".concat(e("Sign-in")," (").concat(d.Schema.compile(n.authTypeTitle||n.authType,{t:e}),")");return function(e){for(var t=1;t<arguments.length;t++){var n=null!=arguments[t]?arguments[t]:{},r=Object.keys(n);"function"==typeof Object.getOwnPropertySymbols&&(r=r.concat(Object.getOwnPropertySymbols(n).filter(function(e){return Object.getOwnPropertyDescriptor(n,e).enumerable}))),r.forEach(function(t){var r;r=n[t],t in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r})}return e}({component:(0,u.createElement)(r,{authenticator:n}),tabTitle:n.title||a},n)}}).filter(function(e){return e});return i().createElement(o.Space,{direction:"vertical",className:(0,r.css)(S())},c.length>1?i().createElement(o.Tabs,{items:c.map(function(e){return{label:e.tabTitle,key:e.name,children:e.component}})}):c.length?i().createElement("div",null,c[0].component):i().createElement(i().Fragment,null),i().createElement(o.Space,{direction:"vertical",className:(0,r.css)(E())},l))};function x(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 O(e,t){return function(e){if(Array.isArray(e))return e}(e)||function(e,t){var n,r,a=null==e?null:"undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(null!=a){var o=[],u=!0,i=!1;try{for(a=a.call(e);!(u=(n=a.next()).done)&&(o.push(n.value),!t||o.length!==t);u=!0);}catch(e){i=!0,r=e}finally{try{u||null==a.return||a.return()}finally{if(i)throw r}}return o}}(e,t)||function(e,t){if(e){if("string"==typeof e)return x(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 x(e,t)}}(e,t)||function(){throw TypeError("Invalid attempt to destructure non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}var j=(0,u.createContext)({});j.displayName="SignupPageContext";var A=function(e){var t=(0,u.useContext)(j);return t[e.authType]={component:e.component},i().createElement(j.Provider,{value:t},e.children)},C=function(){var e=(0,a.usePlugin)(y.default).authTypes.getEntities(),t={},n=!0,r=!1,o=void 0;try{for(var u,i=e[Symbol.iterator]();!(n=(u=i.next()).done);n=!0){var l,c=O(u.value,2),f=c[0],s=c[1];(null==(l=s.components)?void 0:l.SignUpForm)&&(t[f]=s.components.SignUpForm)}}catch(e){r=!0,o=e}finally{try{n||null==i.return||i.return()}finally{if(r)throw o}}return t},I=function(){(0,a.useViewport)(),(0,a.useCurrentDocumentTitle)("Signup");var e=C(),t=O((0,l.useSearchParams)(),1)[0].get("name"),n=((0,f.u)(t)||{}).authType;return e[n]?(0,u.createElement)(e[n],{authenticatorName:t}):i().createElement(l.Navigate,{to:"/not-found",replace:!0})}}}]);