1import{u as P,b as k,k as x,d as E,j as m,L as R}from"./index-DcZatQl_.js";import{f as $,b as j}from"./react-vendor-CfoRXicY.js";import{supabase as _}from"./supabase-CNbjEO5G.js";import{CONNECT_SESSION_KEY as y}from"./AuthConnect-Bo-8Fegx.js";import{i as L}from"./usePhoneLayout-BjfrpXGI.js";import{w as T}from"./coverage-DwQ8SuXr.js";import"./supabase-DHizuabt.js";import"./types-DHgsoueE.js";import"./library-fallback-KpZSCpNH.js";function A(r){if(!r||!r.startsWith("/")||r.startsWith("//"))return"/dashboard";try{const a=new URL(r,window.location.origin);return a.origin!==window.location.origin?"/dashboard":`${a.pathname}${a.search}${a.hash}`||"/dashboard"}catch{return"/dashboard"}}const K=()=>{const{session:r,loading:a}=P(),t=$();return k({title:"Finishing sign-in",description:"Completing your AgentWeb sign-in and sending you back to where you started."}),j.useEffect(()=>{const n=L();if(n&&window.location.pathname!=="/auth/callback")return;const o=new URLSearchParams(window.location.hash.replace(/^#/,"")),u=new URLSearchParams(window.location.search),l=u.get("next"),N=o.get("type"),s=e=>n?o.get(e)??u.get(e):o.get(e),i=n?s("error_code")??s("error"):s("error_code"),d=s("error_description"),c=l==="company-brain-reset"||N==="recovery"||i==="otp_expired",h=e=>n?`${x()==="signin"?"/login":"/signup"}?error=${e}`:"/login?error=auth_failed";if(i){if(c){const e=new URLSearchParams({error:i,message:d||"Email link is invalid or has expired."});t(`/company-brain/reset-password?${e.toString()}`,{replace:!0});return}t(h(/work email/i.test(d??"")?"work_email":"auth_failed"),{replace:!0});return}if(a)return;if(!r){const e=setTimeout(()=>{if(!r){const p=c?"/company-brain/reset-password?error=no_session&message=Open%20a%20fresh%20password%20setup%20link.":h("auth_failed");t(p,{replace:!0})}},2500);return()=>clearTimeout(e)}if(c){t("/company-brain/reset-password",{replace:!0});return}const g=sessionStorage.getItem(y);if(g){sessionStorage.removeItem(y),t(`/auth/connect?session=${encodeURIComponent(g)}`,{replace:!0});return}const f=x()||"signup";if(f==="company_brain"){t("/company-brain",{replace:!0});return}(async()=>{const{data:e,error:p}=await _.from("profiles_safe").select("created_at").single(),S=Date.now(),w=e!=null&&e.created_at?new Date(e.created_at).getTime():null,C=!p&&w!==null&&S-w<6e4;if(f==="signin"&&C){await _.auth.signOut(),t("/signup?no_account=1",{replace:!0});return}const b=A(l??E());t(b==="/onboarding"&&!T(r.user.email)?"/onboarding?plan=payg":b,{replace:!0})})()},[r,a,t]),m.jsxs("div",{className:"flex min-h-screen flex-col items-center justify-center gap-5 bg-aw-bg",role:"status",children:[m.jsx(R,{className:"h-5 w-5 animate-spin text-white/45","aria-hidden":!0}),m.jsx("p",{className:"aw-mono text-[11px] uppercase tracking-[0.24em] text-white/40",children:"Finishing sign-inâ¦"})]})};export{K as default};
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.