# generated by patch-package 6.4.8 on 2022-03-06 12:15:51
#
# command:
# npx patch-package @saas-ui/auth
#
# declared package:
# @saas-ui/auth: ^0.6.1
#
diff --git a/node_modules/@saas-ui/auth/dist/index.modern.js b/node_modules/@saas-ui/auth/dist/index.modern.js
index ee7c337..333a51b 100644
--- a/node_modules/@saas-ui/auth/dist/index.modern.js
+++ b/node_modules/@saas-ui/auth/dist/index.modern.js
@@ -1,2 +1,738 @@
-import*as e from"react";import{usePromise as t}from"@saas-ui/hooks";import{useTheme as n,Alert as r,AlertIcon as l,AlertTitle as o,AlertDescription as a,SimpleGrid as i,Icon as s,omitThemingProps as c,StylesProvider as u,chakra as d,useStyles as m,useColorModeValue as p,Link as E}from"@chakra-ui/react";import{useMultiStyleConfig as f}from"@saas-ui/system";import{Form as h,FormLayout as b,Field as g}from"@saas-ui/forms";import{Button as L}from"@saas-ui/button";const{createContext:v,useState:y,useContext:w,useEffect:S,useCallback:k}=e,P=v(null),O=({onLoadUser:t=(()=>Promise.resolve()),onSignup:n=(()=>Promise.resolve()),onLogin:r=(()=>Promise.resolve()),onVerifyOtp:l=(()=>Promise.resolve()),onLogout:o=(()=>Promise.resolve()),onAuthStateChange:a,onGetToken:i,onResetPassword:s,onUpdatePassword:c,children:u})=>{const[d,m]=y(!1),[p,E]=y(),[f,h]=y(!0);S(()=>{if(a){const e=a(e=>{m(!!e)});return()=>{e()}}},[]),S(()=>{g()},[d]);const b=k(async()=>{try{i&&m(!!await i())}catch(e){m(!1)}},[i]);S(()=>(window.addEventListener("focus",b),b(),()=>{window.removeEventListener("focus",b)}),[b]);const g=k(async()=>{if(d){const e=await t();e?E(e):m(!1)}h(!1)},[t,d]),L=k(async(e,t)=>{const r=await n(e,t);return b(),r},[n]),v=k(async(e,t)=>{const n=await r(e,t);return b(),n},[r]),w=k(async()=>{await o(),E(null),m(!1)},[o]),O=k(async(e,t)=>await l(e,t),[l]),x=k(async(e,t)=>{await(null==s?void 0:s(e,t))},[s]),A=k(async(e,t)=>{await(null==c?void 0:c(e,t))},[c]),V=k(async()=>null==i?void 0:i(),[i]);/*#__PURE__*/return e.createElement(P.Provider,{value:{isAuthenticated:d,isLoggingIn:d&&!p,isLoading:f,user:p,signUp:L,logIn:v,logOut:w,verifyOtp:O,loadUser:g,getToken:V,resetPassword:x,updatePassword:A}},u)},x=()=>w(P),A=()=>x().user,V=({action:e="logIn"}={})=>{const n=x();return t(t=>{var r;return null==(r=n[e])?void 0:r.call(n,t)})},C=()=>{const{signUp:e}=x();return t(t=>e(t))},I=()=>{const{verifyOtp:e}=x();return t(t=>e(t))},_=()=>{const{resetPassword:e}=x();return t(t=>e(t))},T=()=>{const{updatePassword:e}=x();return t(t=>e(t))};function W(){return W=Object.assign||function(e){for(var t=1;t<arguments.length;t++){var n=arguments[t];for(var r in n)Object.prototype.hasOwnProperty.call(n,r)&&(e[r]=n[r])}return e},W.apply(this,arguments)}function F(e,t){if(null==e)return{};var n,r,l={},o=Object.keys(e);for(r=0;r<o.length;r++)t.indexOf(n=o[r])>=0||(l[n]=e[n]);return l}const G=["children"];function R(t){var r;let{children:l}=t,o=F(t,G);const a=W({p:6,colorScheme:"gray"},null==(r=n().components.LoginButton)?void 0:r.defaultProps);/*#__PURE__*/return e.createElement(L,W({},a,o),l)}const U=["title","description"],D=t=>{let{title:n,description:i}=t,s=F(t,U);/*#__PURE__*/return e.createElement(r,W({status:"success",variant:"subtle",flexDirection:"column",alignItems:"center",justifyContent:"center",textAlign:"center"},s),/*#__PURE__*/e.createElement(l,{boxSize:"40px",mr:0}),/*#__PURE__*/e.createElement(o,{mt:4,mb:1,fontSize:"lg"},n),/*#__PURE__*/e.createElement(a,{maxWidth:"sm"},i))},N=["schema","action","onSuccess","onError","onValidationError","submitLabel","defaultValues","renderSuccess","children"];function q({email:t}){/*#__PURE__*/return e.createElement(D,{title:"Check your mailbox!",description:/*#__PURE__*/e.createElement(e.Fragment,null,`We've sent a magic link to ${t||"your email address"}.`/*#__PURE__*/,e.createElement("br",null),"Click on the link to continue.")})}const j=t=>{let{schema:n,action:r="logIn",onSuccess:l=(()=>null),onError:o=(()=>null),onValidationError:a,submitLabel:i="Continue with Email",defaultValues:s,renderSuccess:c=(t=>/*#__PURE__*/e.createElement(q,{email:null==t?void 0:t.email})),children:u}=t,d=F(t,N);const[{isLoading:m,isResolved:p,data:E},f]=V({action:r});return p?c(E):/*#__PURE__*/e.createElement(h,W({schema:n,onSubmit:({email:e})=>f({email:e}).then(l).catch(o),onError:a,defaultValues:W({email:""},s)},d),/*#__PURE__*/e.createElement(b,null,/*#__PURE__*/e.createElement(g,{name:"email",label:"Email",type:"email",rules:{required:!0}}),u,/*#__PURE__*/e.createElement(R,{type:"submit",isLoading:m,isFullWidth:!0,label:i})))},z=["action","schema","onSuccess","onError","onValidationError","submitLabel","defaultValues","children","renderSuccess"],B=t=>{let{action:n="logIn",schema:r,onSuccess:l=(()=>null),onError:o=(()=>null),onValidationError:a,submitLabel:i="Log in",defaultValues:s,children:c,renderSuccess:u=(()=>/*#__PURE__*/e.createElement(D,{title:"Success!",description:"Check your mailbox to verify your account."}))}=t,d=F(t,z);const[{isLoading:m,isResolved:p,data:E},f]=V({action:n});return p&&"signUp"===n?u(E):/*#__PURE__*/e.createElement(h,W({schema:r,onSubmit:e=>f(e).then(l).catch(o),onError:a,defaultValues:W({email:"",password:""},s)},d),/*#__PURE__*/e.createElement(b,null,/*#__PURE__*/e.createElement(g,{name:"email",label:"Email",type:"email",rules:{required:!0}}),/*#__PURE__*/e.createElement(g,{name:"password",label:"Password",type:"password",rules:{required:!0}}),c,/*#__PURE__*/e.createElement(R,{type:"submit",isFullWidth:!0,isLoading:m},i)))},Y=["schema","onSuccess","onError","onValidationError","submitLabel","label","helpText","pinLength","children","renderSuccess"],$=t=>{let{schema:n,onSuccess:r=(()=>null),onError:l=(()=>null),onValidationError:o,submitLabel:a="Verify",label:i,helpText:s,pinLength:c=4,children:u,renderSuccess:d=(()=>/*#__PURE__*/e.createElement(D,{title:"Success!",description:"You are now logged in."}))}=t,m=F(t,Y);const[{isLoading:p,data:E},f]=I();return E?d(E):/*#__PURE__*/e.createElement(h,W({schema:n,onSubmit:e=>f(e).then(r).catch(l),onError:o,defaultValues:{otp:""}},m),/*#__PURE__*/e.createElement(b,null,/*#__PURE__*/e.createElement(g,{name:"otp",label:i,help:s,type:"pin",pinLength:c,rules:{required:!0}}),u,/*#__PURE__*/e.createElement(R,{type:"submit",isFullWidth:!0,isLoading:p},a)))};$.defaultProps={helpText:"You can find your one-time password in the Google Authenticator or Authy app.",submitLabel:"Verify",label:"Your verification code"};const H=["children"];function J(t){var r;let{children:l}=t,o=F(t,H);const a=W({p:6,variant:"outline"},null==(r=n().components.ProviderButton)?void 0:r.defaultProps);/*#__PURE__*/return e.createElement(L,W({},a,o),l)}const K=["providers","redirectTo","label"],M=t=>{let{providers:n,redirectTo:r,label:l="Continue with"}=t,o=F(t,K);const{logIn:a}=x();if(!n)return null;const c=e=>async()=>{await a({provider:e},{redirectTo:r})};/*#__PURE__*/return e.createElement(i,W({spacing:4},o),Object.entries(n).map(([t,n])=>{const{name:r,icon:o,color:a}=n;/*#__PURE__*/return e.createElement(J,{onClick:c(t),color:a,leftIcon:o&&/*#__PURE__*/e.createElement(s,{as:o}),key:t},l," ",r)}))},Q=["schema","onSuccess","onError","onValidationError","submitLabel","label","helpText","children","renderSuccess"],X=t=>{let{schema:n,onSuccess:r=(()=>null),onError:l=(()=>null),onValidationError:o,submitLabel:a,label:i,children:s,renderSuccess:c=(()=>/*#__PURE__*/e.createElement(D,{title:"Success!",description:"Please check your email for instructions to reset your password."}))}=t,u=F(t,Q);const[{isLoading:d,data:m},p]=_();return m?c(m):/*#__PURE__*/e.createElement(h,W({schema:n,onSubmit:e=>p(e).then(r).catch(l),onError:o,defaultValues:{email:""}},u),/*#__PURE__*/e.createElement(b,null,/*#__PURE__*/e.createElement(g,{name:"email",label:i,type:"email",rules:{required:!0}}),s,/*#__PURE__*/e.createElement(R,{type:"submit",isFullWidth:!0,isLoading:d},a)))};X.defaultProps={submitLabel:"Reset password",label:"Your email address"};const Z=["schema","onSuccess","onError","onValidationError","submitLabel","label","confirmLabel","helpText","children"],ee=t=>{let{schema:n,onSuccess:r=(()=>null),onError:l=(()=>null),onValidationError:o,submitLabel:a,label:i,confirmLabel:s,children:c}=t,u=F(t,Z);const[{isLoading:d},m]=T(),p=e.useRef(null),E=e.useCallback(e=>{var t;return e===(null==(t=p.current)?void 0:t.getValues("password"))},[]);/*#__PURE__*/return e.createElement(h,W({schema:n,onSubmit:({password:e})=>m({password:e}).then(r).catch(l),onError:o,defaultValues:{password:"",confirmPassword:""},ref:p},u),/*#__PURE__*/e.createElement(b,null,/*#__PURE__*/e.createElement(g,{name:"password",label:i,type:"password",rules:{required:!0}}),/*#__PURE__*/e.createElement(g,{name:"confirmPassword",label:s,type:"password",rules:{validate:E}}),c,/*#__PURE__*/e.createElement(R,{type:"submit",isFullWidth:!0,isLoading:d},a)))};ee.defaultProps={submitLabel:"Update password",label:"New password",confirmLabel:"Confirm password"};const te=["type","providers","title","providerLabel","dividerLabel","footer"],ne=["label"],re=["children"],le=["title","footer"],oe=["title","footer"],ae=["title","footer"],ie=t=>{const{type:n,providers:r,title:l,providerLabel:o,dividerLabel:a,footer:i}=t,s=F(t,te);let c;return c=/*#__PURE__*/e.createElement("password"===n?B:j,s),/*#__PURE__*/e.createElement(se,null,"string"==typeof l?/*#__PURE__*/e.createElement(ue,null,l):l,r&&/*#__PURE__*/e.createElement(e.Fragment,null,/*#__PURE__*/e.createElement(M,{providers:r,label:o}),/*#__PURE__*/e.createElement(ce,{label:a})),c,i)};ie.defaultProps={type:"magiclink",providerLabel:"Continue with",dividerLabel:"or continue with"};const se=t=>{const{children:n}=t,r=f("AuthForm",t),l=c(t),o=W({display:"flex",flexDirection:"column",alignItems:"stretch",width:"full"},r.container);/*#__PURE__*/return e.createElement(u,{value:r},/*#__PURE__*/e.createElement(d.div,W({__css:o},l),n))},ce=t=>{let{label:n}=t,r=F(t,ne);const l=m(),o={borderBottomWidth:"1px",content:'""',position:"relative",display:"inline-block",width:"50%",top:"50%"},a=W({display:"flex",flexDirection:"row",alignItems:"center",whiteSpace:"nowrap",py:8,color:p("gray.400","whiteAlpha.300"),_before:o,_after:o},l.divider);/*#__PURE__*/return e.createElement(d.div,W({__css:a},r),n&&/*#__PURE__*/e.createElement(d.span,{__css:{display:"inline-block",flexShrink:0,mx:2}},n))},ue=t=>{let{children:n}=t,r=F(t,re);const l=W({fontSize:"2xl",fontWeight:"bold",textAlign:"center",mb:8},m().title);/*#__PURE__*/return e.createElement(d.h2,W({__css:l},r),n)},de=t=>/*#__PURE__*/e.createElement(ie,W({action:"logIn"},t));de.defaultProps={title:"Log in",submitLabel:"Log in"};const me=t=>/*#__PURE__*/e.createElement(ie,W({action:"signUp"},t));me.defaultProps={title:"Sign up",submitLabel:"Sign up"};const pe=t=>{const{title:n,footer:r}=t,l=F(t,le);/*#__PURE__*/return e.createElement(se,null,"string"==typeof n?/*#__PURE__*/e.createElement(ue,null,n):n,/*#__PURE__*/e.createElement($,l),r)};pe.defaultProps={title:"One-time password"};const Ee=t=>{const{title:n,footer:r}=t,l=F(t,oe);/*#__PURE__*/return e.createElement(se,null,"string"==typeof n?/*#__PURE__*/e.createElement(ue,null,n):n,/*#__PURE__*/e.createElement(X,l),r)};Ee.defaultProps={title:"Forgot password"};const fe=t=>{const{title:n,footer:r}=t,l=F(t,ae);/*#__PURE__*/return e.createElement(se,null,"string"==typeof n?/*#__PURE__*/e.createElement(ue,null,n):n,/*#__PURE__*/e.createElement(ee,l),r)};fe.defaultProps={title:"Choose a new password"};const he=["view","providers","signupLink","loginLink","forgotLink","backLink","noAccount","haveAccount"],be={LOGIN:"login",SIGNUP:"signup",FORGOT_PASSWORD:"forgot_password",UPDATE_PASSWORD:"update_password",OTP:"otp"},ge=t=>{const{view:n=be.LOGIN,providers:r,signupLink:l,loginLink:o,forgotLink:a,backLink:i,noAccount:s,haveAccount:c}=t,u=F(t,he),{type:d}=u,[m,p]=e.useState(n);switch(e.useEffect(()=>{p(n)},[n]),m){case be.LOGIN:/*#__PURE__*/return e.createElement(de,W({providers:r,footer:/*#__PURE__*/e.createElement(Le,{onClick:()=>p(be.SIGNUP),label:s,link:l})},u),"password"===d&&("string"==typeof a?/*#__PURE__*/e.createElement(E,{fontSize:"md",color:"muted",float:"right",onClick:()=>p(be.FORGOT_PASSWORD)},a):a));case be.SIGNUP:/*#__PURE__*/return e.createElement(me,W({providers:r,footer:/*#__PURE__*/e.createElement(Le,{onClick:()=>p(be.LOGIN),label:c,link:o})},u));case be.FORGOT_PASSWORD:/*#__PURE__*/return e.createElement(Ee,W({footer:/*#__PURE__*/e.createElement(Le,{onClick:()=>p(be.LOGIN),link:i})},u));case be.UPDATE_PASSWORD:/*#__PURE__*/return e.createElement(fe,u);case be.OTP:/*#__PURE__*/return e.createElement(pe,u)}return null},Le=({label:t,link:n,onClick:r})=>/*#__PURE__*/e.createElement(d.div,{__css:{textAlign:"center",py:8,fontSize:"md"}},t&&/*#__PURE__*/e.createElement(d.span,{color:"muted"},t)," ","string"==typeof n?/*#__PURE__*/e.createElement(E,{onClick:r},n):n);ge.defaultProps={noAccount:"No account yet?",haveAccount:"Already have an account?",signupLink:"Sign up",loginLink:"Log in",forgotLink:"Forgot password?",backLink:"Back to log in"};export{ge as Auth,ie as AuthForm,se as AuthFormContainer,ce as AuthFormDivider,ue as AuthFormTitle,O as AuthProvider,Ee as ForgotPasswordView,R as LoginButton,de as LoginView,j as MagicLinkForm,q as MagicLinkSuccess,$ as OtpForm,pe as OtpView,B as PasswordForm,J as ProviderButton,M as Providers,me as SignupView,fe as UpdatePasswordView,be as VIEWS,x as useAuth,A as useCurrentUser,V as useLogin,I as useOtp,_ as useResetPassword,C as useSignUp,T as useUpdatePassword};
+import * as e from "react";
+import {
+ usePromise as t
+}
+from "@saas-ui/hooks";
+import {
+ useTheme as n, Alert as r, AlertIcon as l, AlertTitle as o, AlertDescription as a, SimpleGrid as i, Icon as s, omitThemingProps as c, StylesProvider as u, chakra as d, useStyles as m, useColorModeValue as p, Link as E
+}
+from "@chakra-ui/react";
+import {
+ useMultiStyleConfig as f
+}
+from "@saas-ui/system";
+import {
+ Form as h, FormLayout as b, Field as g
+}
+from "@saas-ui/forms";
+import {
+ Button as L
+}
+from "@saas-ui/button";
+const {
+ createContext: v,
+ useState: y,
+ useContext: w,
+ useEffect: S,
+ useCallback: k
+} = e, P = v(null), O = ({
+ onLoadUser: t = (() => Promise.resolve()),
+ onSignup: n = (() => Promise.resolve()),
+ onLogin: r = (() => Promise.resolve()),
+ onVerifyOtp: l = (() => Promise.resolve()),
+ onLogout: o = (() => Promise.resolve()),
+ onAuthStateChange: a,
+ onGetToken: i,
+ onResetPassword: s,
+ onUpdatePassword: c,
+ children: u
+}) => {
+ const [d, m] = y(!1), [p, E] = y(), [f, h] = y(!0);
+ S(() => {
+ if (a) {
+ const e = a(e => {
+ m(!!e)
+ });
+ return () => {
+ e()
+ }
+ }
+ }, []), S(() => {
+ g()
+ }, [d]);
+ const b = k(async() => {
+ try {
+ i && m(!!await i())
+ } catch (e) {
+ m(!1)
+ }
+ }, [i]);
+ S(() => (window.addEventListener("focus", b), b(), () => {
+ window.removeEventListener("focus", b)
+ }), [b]);
+ const g = k(async() => {
+ if (d) {
+ const e = await t();
+ e ? E(e) : m(!1)
+ }
+ h(!1)
+ }, [t, d]),
+ L = k(async(e, t) => {
+ const r = await n(e, t);
+ return b(), r
+ }, [n]),
+ v = k(async(e, t) => {
+ try {
+ const n = await r(e, t);
+ console.log(n,n,n)
+ return b(), n
+ } catch(e) {
+ throw e;
+ }
+ }, [r]),
+ w = k(async() => {
+ await o(), E(null), m(!1)
+ }, [o]),
+ O = k(async(e, t) => await l(e, t), [l]),
+ x = k(async(e, t) => {
+ await(null == s ? void 0 : s(e, t))
+ }, [s]),
+ A = k(async(e, t) => {
+ await(null == c ? void 0 : c(e, t))
+ }, [c]),
+ V = k(async() => null == i ? void 0 : i(), [i]); /*#__PURE__*/
+ return e.createElement(P.Provider, {
+ value: {
+ isAuthenticated: d,
+ isLoggingIn: d && !p,
+ isLoading: f,
+ user: p,
+ signUp: L,
+ logIn: v,
+ logOut: w,
+ verifyOtp: O,
+ loadUser: g,
+ getToken: V,
+ resetPassword: x,
+ updatePassword: A
+ }
+ }, u)
+}, x = () => w(P), A = () => x().user, V = ({
+ action: e = "logIn"
+} = {}) => {
+ const n = x();
+ return t(t => {
+ var r;
+ return null == (r = n[e]) ? void 0 : r.call(n, t)
+ })
+}, C = () => {
+ const {
+ signUp: e
+ } = x();
+ return t(t => e(t))
+}, I = () => {
+ const {
+ verifyOtp: e
+ } = x();
+ return t(t => e(t))
+}, _ = () => {
+ const {
+ resetPassword: e
+ } = x();
+ return t(t => e(t))
+}, T = () => {
+ const {
+ updatePassword: e
+ } = x();
+ return t(t => e(t))
+};
+
+function W() {
+ return W = Object.assign || function(e) {
+ for (var t = 1; t < arguments.length; t++) {
+ var n = arguments[t];
+ for (var r in n) Object.prototype.hasOwnProperty.call(n, r) && (e[r] = n[r])
+ }
+ return e
+ }, W.apply(this, arguments)
+}
+
+function F(e, t) {
+ if (null == e) return {};
+ var n, r, l = {},
+ o = Object.keys(e);
+ for (r = 0; r < o.length; r++) t.indexOf(n = o[r]) >= 0 || (l[n] = e[n]);
+ return l
+}
+const G = ["children"];
+
+function R(t) {
+ var r;
+ let {
+ children: l
+ } = t, o = F(t, G);
+ const a = W({
+ p: 6,
+ colorScheme: "gray"
+ }, null == (r = n().components.LoginButton) ? void 0 : r.defaultProps); /*#__PURE__*/
+ return e.createElement(L, W({}, a, o), l)
+}
+const U = ["title", "description"],
+ D = t => {
+ let {
+ title: n,
+ description: i
+ } = t, s = F(t, U); /*#__PURE__*/
+ return e.createElement(r, W({
+ status: "success",
+ variant: "subtle",
+ flexDirection: "column",
+ alignItems: "center",
+ justifyContent: "center",
+ textAlign: "center"
+ }, s), /*#__PURE__*/ e.createElement(l, {
+ boxSize: "40px",
+ mr: 0
+ }), /*#__PURE__*/ e.createElement(o, {
+ mt: 4,
+ mb: 1,
+ fontSize: "lg"
+ }, n), /*#__PURE__*/ e.createElement(a, {
+ maxWidth: "sm"
+ }, i))
+ },
+ N = ["schema", "action", "onSuccess", "onError", "onValidationError", "submitLabel", "defaultValues", "renderSuccess", "children"];
+
+function q({
+ email: t
+}) { /*#__PURE__*/
+ return e.createElement(D, {
+ title: "Check your mailbox!",
+ description: /*#__PURE__*/ e.createElement(e.Fragment, null, `We've sent a magic link to ${t||"your email address"}.` /*#__PURE__*/ , e.createElement("br", null), "Click on the link to continue.")
+ })
+}
+const j = t => {
+ let {
+ schema: n,
+ action: r = "logIn",
+ onSuccess: l = (() => null),
+ onError: o = (() => null),
+ onValidationError: a,
+ submitLabel: i = "Continue with Email",
+ defaultValues: s,
+ renderSuccess: c = (t => /*#__PURE__*/ e.createElement(q, {
+ email: null == t ? void 0 : t.email
+ })),
+ children: u
+ } = t, d = F(t, N);
+ const [{
+ isLoading: m,
+ isResolved: p,
+ isRejected,
+ error,
+ data: E
+ }, f] = V({
+ action: r
+ });
+ e.useEffect(() => {
+ if(isRejected) {
+ o(error);
+ }
+ if(p) {
+ l();
+ }
+ }, [error, isRejected, p]);
+ return p ? c(E) : /*#__PURE__*/ e.createElement(h, W({
+ schema: n,
+ onSubmit: ({
+ email: e
+ }) => f({
+ email: e
+ }),
+ onError: a,
+ defaultValues: W({
+ email: ""
+ }, s)
+ }, d), /*#__PURE__*/ e.createElement(b, null, /*#__PURE__*/ e.createElement(g, {
+ name: "email",
+ label: "Email",
+ type: "email",
+ rules: {
+ required: !0
+ }
+ }), u, /*#__PURE__*/ e.createElement(R, {
+ type: "submit",
+ isLoading: m,
+ isFullWidth: !0,
+ label: i
+ })))
+ },
+ z = ["action", "schema", "onSuccess", "onError", "onValidationError", "submitLabel", "defaultValues", "children", "renderSuccess"],
+ B = t => {
+ let {
+ action: n = "logIn",
+ schema: r,
+ onSuccess: l = (() => null),
+ onError: o = (() => null),
+ onValidationError: a,
+ submitLabel: i = "Log in",
+ defaultValues: s,
+ children: c,
+ renderSuccess: u = (() => /*#__PURE__*/ e.createElement(D, {
+ title: "Success!",
+ description: "Check your mailbox to verify your account."
+ }))
+ } = t, d = F(t, z);
+ const [{
+ isLoading: m,
+ isResolved: p,
+ isRejected,
+ error,
+ data: E
+ }, f] = V({
+ action: n
+ });
+ e.useEffect(() => {
+ if(isRejected) {
+ o(error);
+ }
+ if(p) {
+ l();
+ }
+ }, [error, isRejected, p]);
+ return p && "signUp" === n ? u(E) : /*#__PURE__*/ e.createElement(h, W({
+ schema: r,
+ onSubmit: e => f(e),
+ onError: a,
+ defaultValues: W({
+ email: "",
+ password: ""
+ }, s)
+ }, d), /*#__PURE__*/ e.createElement(b, null, /*#__PURE__*/ e.createElement(g, {
+ name: "email",
+ label: "Email",
+ type: "email",
+ rules: {
+ required: !0
+ }
+ }), /*#__PURE__*/ e.createElement(g, {
+ name: "password",
+ label: "Password",
+ type: "password",
+ rules: {
+ required: !0
+ }
+ }), c, /*#__PURE__*/ e.createElement(R, {
+ type: "submit",
+ isFullWidth: !0,
+ isLoading: m
+ }, i)))
+ },
+ Y = ["schema", "onSuccess", "onError", "onValidationError", "submitLabel", "label", "helpText", "pinLength", "children", "renderSuccess"],
+ $ = t => {
+ let {
+ schema: n,
+ onSuccess: r = (() => null),
+ onError: l = (() => null),
+ onValidationError: o,
+ submitLabel: a = "Verify",
+ label: i,
+ helpText: s,
+ pinLength: c = 4,
+ children: u,
+ renderSuccess: d = (() => /*#__PURE__*/ e.createElement(D, {
+ title: "Success!",
+ description: "You are now logged in."
+ }))
+ } = t, m = F(t, Y);
+ const [{
+ isLoading: p,
+ data: E
+ }, f] = I();
+ return E ? d(E) : /*#__PURE__*/ e.createElement(h, W({
+ schema: n,
+ onSubmit: e => f(e).then(r).catch(l),
+ onError: o,
+ defaultValues: {
+ otp: ""
+ }
+ }, m), /*#__PURE__*/ e.createElement(b, null, /*#__PURE__*/ e.createElement(g, {
+ name: "otp",
+ label: i,
+ help: s,
+ type: "pin",
+ pinLength: c,
+ rules: {
+ required: !0
+ }
+ }), u, /*#__PURE__*/ e.createElement(R, {
+ type: "submit",
+ isFullWidth: !0,
+ isLoading: p
+ }, a)))
+ };
+$.defaultProps = {
+ helpText: "You can find your one-time password in the Google Authenticator or Authy app.",
+ submitLabel: "Verify",
+ label: "Your verification code"
+};
+const H = ["children"];
+
+function J(t) {
+ var r;
+ let {
+ children: l
+ } = t, o = F(t, H);
+ const a = W({
+ p: 6,
+ variant: "outline"
+ }, null == (r = n().components.ProviderButton) ? void 0 : r.defaultProps); /*#__PURE__*/
+ return e.createElement(L, W({}, a, o), l)
+}
+const K = ["providers", "redirectTo", "label"],
+ M = t => {
+ let {
+ providers: n,
+ redirectTo: r,
+ label: l = "Continue with"
+ } = t, o = F(t, K);
+ const {
+ logIn: a
+ } = x();
+ if (!n) return null;
+ const c = e => async() => {
+ await a({
+ provider: e
+ }, {
+ redirectTo: r
+ })
+ }; /*#__PURE__*/
+ return e.createElement(i, W({
+ spacing: 4
+ }, o), Object.entries(n).map(([t, n]) => {
+ const {
+ name: r,
+ icon: o,
+ color: a
+ } = n; /*#__PURE__*/
+ return e.createElement(J, {
+ onClick: c(t),
+ color: a,
+ leftIcon: o && /*#__PURE__*/ e.createElement(s, {
+ as: o
+ }),
+ key: t
+ }, l, " ", r)
+ }))
+ },
+ Q = ["schema", "onSuccess", "onError", "onValidationError", "submitLabel", "label", "helpText", "children", "renderSuccess"],
+ X = t => {
+ let {
+ schema: n,
+ onSuccess: r = (() => null),
+ onError: l = (() => null),
+ onValidationError: o,
+ submitLabel: a,
+ label: i,
+ children: s,
+ renderSuccess: c = (() => /*#__PURE__*/ e.createElement(D, {
+ title: "Success!",
+ description: "Please check your email for instructions to reset your password."
+ }))
+ } = t, u = F(t, Q);
+ const [{
+ isLoading: d,
+ data: m
+ }, p] = _();
+ return m ? c(m) : /*#__PURE__*/ e.createElement(h, W({
+ schema: n,
+ onSubmit: e => p(e).then(r).catch(l),
+ onError: o,
+ defaultValues: {
+ email: ""
+ }
+ }, u), /*#__PURE__*/ e.createElement(b, null, /*#__PURE__*/ e.createElement(g, {
+ name: "email",
+ label: i,
+ type: "email",
+ rules: {
+ required: !0
+ }
+ }), s, /*#__PURE__*/ e.createElement(R, {
+ type: "submit",
+ isFullWidth: !0,
+ isLoading: d
+ }, a)))
+ };
+X.defaultProps = {
+ submitLabel: "Reset password",
+ label: "Your email address"
+};
+const Z = ["schema", "onSuccess", "onError", "onValidationError", "submitLabel", "label", "confirmLabel", "helpText", "children"],
+ ee = t => {
+ let {
+ schema: n,
+ onSuccess: r = (() => null),
+ onError: l = (() => null),
+ onValidationError: o,
+ submitLabel: a,
+ label: i,
+ confirmLabel: s,
+ children: c
+ } = t, u = F(t, Z);
+ const [{
+ isLoading: d
+ }, m] = T(), p = e.useRef(null), E = e.useCallback(e => {
+ var t;
+ return e === (null == (t = p.current) ? void 0 : t.getValues("password"))
+ }, []); /*#__PURE__*/
+ return e.createElement(h, W({
+ schema: n,
+ onSubmit: ({
+ password: e
+ }) => m({
+ password: e
+ }).then(r).catch(l),
+ onError: o,
+ defaultValues: {
+ password: "",
+ confirmPassword: ""
+ },
+ ref: p
+ }, u), /*#__PURE__*/ e.createElement(b, null, /*#__PURE__*/ e.createElement(g, {
+ name: "password",
+ label: i,
+ type: "password",
+ rules: {
+ required: !0
+ }
+ }), /*#__PURE__*/ e.createElement(g, {
+ name: "confirmPassword",
+ label: s,
+ type: "password",
+ rules: {
+ validate: E
+ }
+ }), c, /*#__PURE__*/ e.createElement(R, {
+ type: "submit",
+ isFullWidth: !0,
+ isLoading: d
+ }, a)))
+ };
+ee.defaultProps = {
+ submitLabel: "Update password",
+ label: "New password",
+ confirmLabel: "Confirm password"
+};
+const te = ["type", "providers", "title", "providerLabel", "dividerLabel", "footer"],
+ ne = ["label"],
+ re = ["children"],
+ le = ["title", "footer"],
+ oe = ["title", "footer"],
+ ae = ["title", "footer"],
+ ie = t => {
+ const {
+ type: n,
+ providers: r,
+ title: l,
+ providerLabel: o,
+ dividerLabel: a,
+ footer: i
+ } = t, s = F(t, te);
+ let c;
+ return c = /*#__PURE__*/ e.createElement("password" === n ? B : j, s), /*#__PURE__*/ e.createElement(se, null, "string" == typeof l ? /*#__PURE__*/ e.createElement(ue, null, l) : l, r && /*#__PURE__*/ e.createElement(e.Fragment, null, /*#__PURE__*/ e.createElement(M, {
+ providers: r,
+ label: o
+ }), /*#__PURE__*/ e.createElement(ce, {
+ label: a
+ })), c, i)
+ };
+ie.defaultProps = {
+ type: "magiclink",
+ providerLabel: "Continue with",
+ dividerLabel: "or continue with"
+};
+const se = t => {
+ const {
+ children: n
+ } = t, r = f("AuthForm", t), l = c(t), o = W({
+ display: "flex",
+ flexDirection: "column",
+ alignItems: "stretch",
+ width: "full"
+ }, r.container); /*#__PURE__*/
+ return e.createElement(u, {
+ value: r
+ }, /*#__PURE__*/ e.createElement(d.div, W({
+ __css: o
+ }, l), n))
+ },
+ ce = t => {
+ let {
+ label: n
+ } = t, r = F(t, ne);
+ const l = m(),
+ o = {
+ borderBottomWidth: "1px",
+ content: '""',
+ position: "relative",
+ display: "inline-block",
+ width: "50%",
+ top: "50%"
+ },
+ a = W({
+ display: "flex",
+ flexDirection: "row",
+ alignItems: "center",
+ whiteSpace: "nowrap",
+ py: 8,
+ color: p("gray.400", "whiteAlpha.300"),
+ _before: o,
+ _after: o
+ }, l.divider); /*#__PURE__*/
+ return e.createElement(d.div, W({
+ __css: a
+ }, r), n && /*#__PURE__*/ e.createElement(d.span, {
+ __css: {
+ display: "inline-block",
+ flexShrink: 0,
+ mx: 2
+ }
+ }, n))
+ },
+ ue = t => {
+ let {
+ children: n
+ } = t, r = F(t, re);
+ const l = W({
+ fontSize: "2xl",
+ fontWeight: "bold",
+ textAlign: "center",
+ mb: 8
+ }, m().title); /*#__PURE__*/
+ return e.createElement(d.h2, W({
+ __css: l
+ }, r), n)
+ },
+ de = t => /*#__PURE__*/ e.createElement(ie, W({
+ action: "logIn"
+ }, t));
+de.defaultProps = {
+ title: "Log in",
+ submitLabel: "Log in"
+};
+const me = t => /*#__PURE__*/ e.createElement(ie, W({
+ action: "signUp"
+}, t));
+me.defaultProps = {
+ title: "Sign up",
+ submitLabel: "Sign up"
+};
+const pe = t => {
+ const {
+ title: n,
+ footer: r
+ } = t, l = F(t, le); /*#__PURE__*/
+ return e.createElement(se, null, "string" == typeof n ? /*#__PURE__*/ e.createElement(ue, null, n) : n, /*#__PURE__*/ e.createElement($, l), r)
+};
+pe.defaultProps = {
+ title: "One-time password"
+};
+const Ee = t => {
+ const {
+ title: n,
+ footer: r
+ } = t, l = F(t, oe); /*#__PURE__*/
+ return e.createElement(se, null, "string" == typeof n ? /*#__PURE__*/ e.createElement(ue, null, n) : n, /*#__PURE__*/ e.createElement(X, l), r)
+};
+Ee.defaultProps = {
+ title: "Forgot password"
+};
+const fe = t => {
+ const {
+ title: n,
+ footer: r
+ } = t, l = F(t, ae); /*#__PURE__*/
+ return e.createElement(se, null, "string" == typeof n ? /*#__PURE__*/ e.createElement(ue, null, n) : n, /*#__PURE__*/ e.createElement(ee, l), r)
+};
+fe.defaultProps = {
+ title: "Choose a new password"
+};
+const he = ["view", "providers", "signupLink", "loginLink", "forgotLink", "backLink", "noAccount", "haveAccount"],
+ be = {
+ LOGIN: "login",
+ SIGNUP: "signup",
+ FORGOT_PASSWORD: "forgot_password",
+ UPDATE_PASSWORD: "update_password",
+ OTP: "otp"
+ },
+ ge = t => {
+ const {
+ view: n = be.LOGIN,
+ providers: r,
+ signupLink: l,
+ loginLink: o,
+ forgotLink: a,
+ backLink: i,
+ noAccount: s,
+ haveAccount: c
+ } = t, u = F(t, he), {
+ type: d
+ } = u, [m, p] = e.useState(n);
+ switch (e.useEffect(() => {
+ p(n)
+ }, [n]), m) {
+ case be.LOGIN:
+ /*#__PURE__*/ return e.createElement(de, W({
+ providers: r,
+ footer: /*#__PURE__*/ e.createElement(Le, {
+ onClick: () => p(be.SIGNUP),
+ label: s,
+ link: l
+ })
+ }, u), "password" === d && ("string" == typeof a ? /*#__PURE__*/ e.createElement(E, {
+ fontSize: "md",
+ color: "muted",
+ float: "right",
+ onClick: () => p(be.FORGOT_PASSWORD)
+ }, a) : a));
+ case be.SIGNUP:
+ /*#__PURE__*/ return e.createElement(me, W({
+ providers: r,
+ footer: /*#__PURE__*/ e.createElement(Le, {
+ onClick: () => p(be.LOGIN),
+ label: c,
+ link: o
+ })
+ }, u));
+ case be.FORGOT_PASSWORD:
+ /*#__PURE__*/ return e.createElement(Ee, W({
+ footer: /*#__PURE__*/ e.createElement(Le, {
+ onClick: () => p(be.LOGIN),
+ link: i
+ })
+ }, u));
+ case be.UPDATE_PASSWORD:
+ /*#__PURE__*/ return e.createElement(fe, u);
+ case be.OTP:
+ /*#__PURE__*/ return e.createElement(pe, u)
+ }
+ return null
+ },
+ Le = ({
+ label: t,
+ link: n,
+ onClick: r
+ }) => /*#__PURE__*/ e.createElement(d.div, {
+ __css: {
+ textAlign: "center",
+ py: 8,
+ fontSize: "md"
+ }
+ }, t && /*#__PURE__*/ e.createElement(d.span, {
+ color: "muted"
+ }, t), " ", "string" == typeof n ? /*#__PURE__*/ e.createElement(E, {
+ onClick: r
+ }, n) : n);
+ge.defaultProps = {
+ noAccount: "No account yet?",
+ haveAccount: "Already have an account?",
+ signupLink: "Sign up",
+ loginLink: "Log in",
+ forgotLink: "Forgot password?",
+ backLink: "Back to log in"
+};
+export {
+ ge as Auth, ie as AuthForm, se as AuthFormContainer, ce as AuthFormDivider, ue as AuthFormTitle, O as AuthProvider, Ee as ForgotPasswordView, R as LoginButton, de as LoginView, j as MagicLinkForm, q as MagicLinkSuccess, $ as OtpForm, pe as OtpView, B as PasswordForm, J as ProviderButton, M as Providers, me as SignupView, fe as UpdatePasswordView, be as VIEWS, x as useAuth, A as useCurrentUser, V as useLogin, I as useOtp, _ as useResetPassword, C as useSignUp, T as useUpdatePassword
+};
//# sourceMappingURL=index.modern.js.map
\ No newline at end of file
diff --git a/node_modules/@saas-ui/auth/src/components/password-form.tsx b/node_modules/@saas-ui/auth/src/components/password-form.tsx
index 5cc0dbc..d9346cd 100644
--- a/node_modules/@saas-ui/auth/src/components/password-form.tsx
+++ b/node_modules/@saas-ui/auth/src/components/password-form.tsx
@@ -42,10 +42,10 @@ export const PasswordForm: React.FC<PasswordFormProps> = ({
),
...formProps
}) => {
- const [{ isLoading, isResolved, data }, submit] = useLogin({ action })
+ const [{ isLoading, isResolved, data, isRejected, error }, submit] = useLogin({ action })
const handleSubmit = (params: SubmitParams) => {
- return submit(params).then(onSuccess).catch(onError)
+ return submit(params)
}
// Show a default success message on signup.
@@ -53,6 +53,14 @@ export const PasswordForm: React.FC<PasswordFormProps> = ({
return renderSuccess(data)
}
+ React.useEffect(() => {
+ if(isRejected) {
+ onError(error);
+ } else if(isResolved) {
+ onSuccess(data);
+ }
+ }, [error, isRejected, isResolved, data])
+
return (
<Form
schema={schema}
diff --git a/node_modules/@saas-ui/auth/src/provider.tsx b/node_modules/@saas-ui/auth/src/provider.tsx
index 5e924ac..9177f3b 100644
--- a/node_modules/@saas-ui/auth/src/provider.tsx
+++ b/node_modules/@saas-ui/auth/src/provider.tsx
@@ -191,9 +191,13 @@ export const AuthProvider: React.FC<AuthProviderProps> = ({
const logIn = useCallback(
async (params: AuthParams, options?: AuthOptions) => {
- const result = await onLogin(params, options)
- checkAuth() // In case the auth service authenticates the user directly.
- return result
+ try {
+ const result = await onLogin(params, options)
+ checkAuth() // In case the auth service authenticates the user directly.
+ return result
+ } catch (err) {
+ throw err
+ }
},
[onLogin]
)