UNPKG

@accounter/client

Version:
1 lines 3.09 kB
import{s as e}from"./dist-C51EwTaa.js";import{i as t,o as n}from"./utils-DdVdMk8X.js";import{_ as r,t as i}from"./routes-DUvpW9-n.js";import{n as a}from"./auth0-react.esm-BrucYGp4.js";import{t as o}from"./button-Dzp2INW0.js";import{n as s,r as c}from"./index-CL8-JoMZ.js";var l=e(n(),1),u=t(),d=2,f=750,p=new Map,m=new Map;function h(e){if(e instanceof Error)return e;let t=Error(`Unknown authentication error`);if(typeof e==`object`&&e){let n=e;typeof n.error==`string`&&(t.error=n.error),typeof n.message==`string`&&n.message.length>0&&(t.message=n.message)}return t}function g(e){return new Promise(t=>{setTimeout(t,e)})}function _(e,t){let n=p.get(e);if(n)return n;let r=v(t);return p.set(e,r),r}async function v(e,{maxAttempts:t=d,retryDelayMs:n=f}={}){let r;for(let i=0;i<=t;i+=1)try{return await e()}catch(e){if(r=h(e),!c(r)||i>=t)throw r;await g(n*(i+1))}throw r}function y(){let{handleRedirectCallback:e,isLoading:t,error:n,isAuthenticated:c,loginWithRedirect:d}=a(),f=r(),[p,g]=(0,l.useState)(null),v=typeof window>`u`?``:window.location.origin,y=typeof window>`u`?``:window.location.search,b=typeof window>`u`?null:new URLSearchParams(window.location.search),x=b?.has(`code`)&&b?.has(`state`);(0,l.useEffect)(()=>{if(c&&!x){let e=sessionStorage.getItem(`auth:invitationReturnTo`),t=sessionStorage.getItem(`auth:returnTo`),n=sessionStorage.getItem(`auth:lastResolvedReturnTo`),r=e??t??n??i.CHARGES.ROOT;sessionStorage.removeItem(`auth:invitationReturnTo`),sessionStorage.removeItem(`auth:returnTo`),sessionStorage.removeItem(`auth:lastResolvedReturnTo`),f(r,{replace:!0});return}if(n){g(h(n));return}if(t)return;let r=!1;return(async()=>{try{let t=await _(y,e);if(r)return;let n=m.get(y);if(n){sessionStorage.removeItem(`auth:invitationReturnTo`),sessionStorage.removeItem(`auth:returnTo`),sessionStorage.removeItem(`auth:lastResolvedReturnTo`),f(n,{replace:!0});return}let a=t,o=sessionStorage.getItem(`auth:invitationReturnTo`),s=sessionStorage.getItem(`auth:returnTo`),c=o??a.appState?.returnTo??s??i.HOME;m.set(y,c),sessionStorage.setItem(`auth:lastResolvedReturnTo`,c),sessionStorage.removeItem(`auth:invitationReturnTo`),sessionStorage.removeItem(`auth:returnTo`),f(c,{replace:!0})}catch(e){r||g(h(e))}})(),()=>{r=!0}},[c,x,y,t,n,e,f]);let S=p??(n?h(n):null);if(S){let e=s(S);return(0,u.jsx)(`div`,{className:`flex items-center justify-center h-screen`,children:(0,u.jsxs)(`div`,{className:`text-center max-w-sm space-y-4`,children:[(0,u.jsx)(`h1`,{className:`text-2xl font-bold`,children:`Login Failed`}),(0,u.jsx)(`p`,{className:`text-muted-foreground`,children:e}),(0,u.jsxs)(`div`,{className:`flex gap-2 justify-center`,children:[(0,u.jsx)(o,{onClick:()=>{let e=sessionStorage.getItem(`auth:returnTo`);return d({authorizationParams:{audience:void 0,scope:`openid profile email offline_access`,redirect_uri:`${v}${i.AUTH_CALLBACK}`},appState:{returnTo:e??i.HOME}})},children:`Try Again`}),(0,u.jsx)(o,{variant:`outline`,onClick:()=>f(i.LOGIN),children:`Back to Login`})]})]})})}return(0,u.jsx)(`div`,{children:`Processing authentication...`})}export{y as AuthCallbackPage};