1import{u as I,a as N,r as n,j as r}from"./c-vendor-react-DxK3Ac_g.js";import{g as A,Y as k,L}from"./app.js";import{l as b}from"./c-returnTo-BBwegY1L.js";function R(stage,phase,failure){const error=failure;const httpStatus=Number.isInteger(error?.status)&&error.status>=100&&error.status<=599?error.status:void 0;const reason=stage==="TIMEOUT"?"deadline":stage==="STORE"||stage==="REQUEST"&&(error?.name==="SecurityError"||error?.name==="QuotaExceededError")?"storage":error?.code==="network_error"?"network":httpStatus?"http":error?.code==="invalid_response"?"invalid_response":"unknown";const exceptionKind=stage==="REQUEST"&&reason==="unknown"?error?.name==="TypeError"?"TypeError":error?.name==="AbortError"?"AbortError":error?.name==="SyntaxError"?"SyntaxError":"Other":void 0;window.dispatchEvent(new CustomEvent("loaded:login-sso-failure",{detail:{stage,phase,reason,...httpStatus?{httpStatus}:{},...exceptionKind?{exceptionKind}:{}}}))}const j=12e3,_="Could not reach Loaded ID. Please try again.";function U(){var x;const{beginSso:o,isAuthenticated:i,loading:c}=A(),e=I(),l=N(),p=l.state,u=b(((x=p==null?void 0:p.from)==null?void 0:x.pathname)??new URLSearchParams(l.search).get("returnTo")),T=u==="/vpn"||u.startsWith("/app?promo=vpn"),[h,m]=n.useState(null),E=n.useRef(!1),w=n.useRef(),d=n.useRef(null),a=n.useCallback(()=>{window.clearTimeout(w.current),w.current=void 0},[]),s=n.useCallback(()=>{const t=d.current;d.current=null,t&&(window.clearTimeout(t.timer),t.controller.abort())},[]);n.useEffect(()=>()=>{a(),s(),E.current=!1},[a,s]);const g=n.useCallback(async()=>{a(),s(),E.current=!0,m(null);const t={controller:new AbortController,timer:void 0};d.current=t;let f="STORE";try{sessionStorage.setItem("loaded.sso.dest",u),f="REQUEST",t.timer=window.setTimeout(()=>{d.current===t&&(s(),R("TIMEOUT","REQUEST"),m(_))},j);const v=await o(t.controller.signal);if(d.current!==t)return;let S;try{if(S=new URL(v),S.origin!=="https://id.loaded.ai")throw new Error}catch{throw Object.assign(new Error("Invalid SSO response"),{code:"invalid_response"})}f="NAVIGATE",window.location.replace(S.href),s()}catch(v){if(d.current!==t)return;s(),R(f,f==="NAVIGATE"?"NAVIGATE":"REQUEST",v),m(_)}},[o,u,a,s]);return n.useEffect(()=>{if(!c){if(a(),i){s(),e(u,{replace:!0});return}E.current||g()}},[c,i,e,u,g,a,s]),n.useEffect(()=>{if(!(!c||i||h||E.current))return w.current=window.setTimeout(()=>{E.current=!0,R("TIMEOUT","RESTORE"),m(_)},j),a},[c,i,h,a]),h?r.jsx("div",{className:"auth",children:r.jsxs("div",{className:"auth__card",children:[r.jsx("h1",{className:"auth__title",children:"Sign in to Loaded"}),r.jsx("p",{className:"auth__error",children:h}),r.jsx(k,{variant:"primary",block:!0,size:"lg",onClick:g,children:"Try again"}),r.jsx("p",{className:"auth__alt",children:r.jsx("a",{href:"https://id.loaded.ai/login",children:"Go to Loaded ID directly"})}),r.jsx("p",{className:"auth__alt",children:r.jsxs("a",{href:T?"/vpn":"/",onClick:t=>{t.preventDefault(),e(T?"/vpn":"/",{replace:!0})},children:["Back to ",T?"VPN":"Loaded"]})})]})}):r.jsx(L,{label:"Taking you to Loaded IDâ¦"})}export{U as Login};
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.