PageSourceSearch

https://equilybrium.health/assets/OAuth2Callback-CCHvYuG5.js

js equilybrium.health collected 2026-10-02 01:56:13 UTC 7,299 bytes, 1 lines download raw bytes

1var S=(m,h,s)=>new Promise((l,g)=>{var f=r=>{try{w(s.next(r))}catch(j){g(j)}},N=r=>{try{w(s.throw(r))}catch(j){g(j)}},w=r=>r.done?l(r.value):Promise.resolve(r.value).then(f,N);w((s=s.apply(m,h)).next())});import{u as Z,r as k,j as e}from"./react-vendor-BEafpyAm.js";import{u as $,C,e as A,f as O,h as E,i as I,A as z,r as F,B as M,o,s as d,au as V,av as ee,g as G}from"./index-o6Y4MR8m.js";import{n as te}from"./oauthProviderMap-DFOkVdNp.js";import{i as se}from"./ssoSignupBlocked-D9r-dJiB.js";import{a3 as ae,a6 as H,a2 as re,C as ie}from"./icons-vendor-DBipXAa1.js";import"./crypto-vendor-DdVgyv-Y.js";import"./react-query-vendor-BhLAuXR4.js";import"./recharts-vendor-C3BwgIm8.js";import"./supabase-vendor-DUUDoC-1.js";import"./date-fns-core-p4ULazqZ.js";import"./date-fns-locales-Csbs7Iu2.js";const je=({onSuccess:m,onError:h})=>{const{t:s}=$(),l=Z(),[g,f]=k.useState("loading"),[N,w]=k.useState(""),[r,j]=k.useState(null);k.useEffect(()=>{S(null,null,function*(){var D,P,R,U;try{f("loading");const x=new URLSearchParams(window.location.search),p=new URLSearchParams(window.location.hash.substring(1)),B=x.get("error")||p.get("error");if(B){const a=x.get("error_description")||p.get("error_description")||B;throw new Error(a)}const K=x.has("code"),Q=p.has("access_token");if(K||Q){o.info("[OAuth] Waiting for Supabase to process auth callback..."),yield new Promise(t=>setTimeout(t,1e3));let{data:{session:a},error:y}=yield d.auth.getSession();if(y)throw new Error(y.message);if(a||(o.info("[OAuth] No session yet, waiting for auth state change..."),a=yield new Promise((t,c)=>{const n=setTimeout(()=>{u.unsubscribe(),c(new Error("Authentication timeout - please try again"))},1e4),{data:{subscription:u}}=d.auth.onAuthStateChange((v,b)=>{v==="SIGNED_IN"&&b&&(clearTimeout(n),u.unsubscribe(),t(b))})})),a!=null&&a.user){const t=a.user,c=((D=t.app_metadata)==null?void 0:D.provider)||"google";j({name:((P=t.user_metadata)==null?void 0:P.full_name)||((R=t.user_metadata)==null?void 0:R.name)||((U=t.email)==null?void 0:U.split("@")[0])||"User",email:t.email||"",role:"user",provider:c}),f("success"),m==null||m(),setTimeout(()=>S(null,null,function*(){var v,b,T;const n=sessionStorage.getItem("auth_redirect_url");sessionStorage.removeItem("auth_redirect_url");const{data:u}=yield d.from("company_users").select("id, user_type").eq("user_id",t.id).maybeSingle();if(u){const i=G((u==null?void 0:u.user_type)||null),_=n||i;o.debug("[OAuth] Existing user - redirect target",{storedRedirectUrl:n,target:_}),l(_,{replace:!0})}else{let i=null,_=!1;try{i=yield V(t.email||""),_=!i.allowed}catch(Y){o.warn("[OAuth] Fraud validation unavailable (fail-open):",Y)}if(_)throw o.warn("[OAuth] Fraud validation blocked OAuth signup:",{reason:i==null?void 0:i.code}),yield d.auth.signOut(),new Error("Signup blocked due to security validation");const L=te(c),{error:W}=yield d.from("company_users").upsert({id:t.id,user_id:t.id,email:t.email,full_name:((v=t.user_metadata)==null?void 0:v.full_name)||((b=t.user_metadata)==null?void 0:b.name)||((T=t.email)==null?void 0:T.split("@")[0]),user_type:"individual",is_individual_user:!0,subscription_status:"trial",subscription_tier:"b2c_trial",trial_started_at:new Date().toISOString(),trial_ends_at:new Date(Date.now()+720*60*60*1e3).toISOString(),payment_status:"unpaid",oauth_provider:L.oauthProvider,created_via:L.createdVia,email_verified:!0,email_verified_at:new Date().toISOString()},{onConflict:"user_id"});W?o.error("[OAuth] Error creating B2C user record:",W):i!=null&&i.attemptId&&ee(i.attemptId,t.id,i.fingerprint).catch(()=>{});const q=n&&n.startsWith("/get-started")?n:"/get-started";o.debug("[OAuth] New user - redirecting to onboarding",{target:q}),l(q,{replace:!0})}}),2e3)}else throw new Error("No session found after authentication")}else{o.info("[OAuth] No OAuth params — checking for existing session");const{data:{session:a}}=yield d.auth.getSession();if(a!=null&&a.user){const y=a.user;o.info("[OAuth] Existing session found, routing without error");const t=sessionStorage.getItem("auth_redirect_url");sessionStorage.removeItem("auth_redirect_url");const{data:c}=yield d.from("company_users").select("user_type").eq("user_id",y.id).maybeSingle();if(c){const n=G((c==null?void 0:c.user_type)||null);l(t||n,{replace:!0})}else{const n=t&&t.startsWith("/get-started")?t:"/get-started";l(n,{replace:!0})}return}throw new Error("No authentication parameters found")}}catch(x){const p=x instanceof Error?x.message:"Unknown error occurred";w(p),f("error"),h==null||h(p)}})},[l,m,h]);const X=()=>{window.location.reload()},J=()=>{l("/login")};return g==="loading"?e.jsx("div",{className:"min-h-screen flex items-center justify-center bg-gray-50",children:e.jsxs(C,{className:"w-full max-w-md",children:[e.jsxs(A,{className:"text-center",children:[e.jsxs(O,{className:"flex items-center justify-center gap-2",children:[e.jsx(ae,{className:"h-6 w-6 animate-spin"}),s("oauth.callback.processing")]}),e.jsx(E,{children:s("oauth.callback.processingDesc")})]}),e.jsx(I,{className:"text-center",children:e.jsxs("div",{className:"space-y-4",children:[e.jsx("div",{className:"flex justify-center",children:e.jsx("div",{className:"animate-spin rounded-full h-8 w-8 border-b-2 border-blue-600"})}),e.jsx("p",{className:"text-sm text-gray-600",children:s("oauth.callback.connecting")})]})})]})}):g==="success"?e.jsx("div",{className:"min-h-screen flex items-center justify-center bg-gray-50",children:e.jsxs(C,{className:"w-full max-w-md",children:[e.jsxs(A,{className:"text-center",children:[e.jsxs(O,{className:"flex items-center justify-center gap-2 text-green-600",children:[e.jsx(H,{className:"h-6 w-6"}),s("oauth.callback.success")]}),e.jsx(E,{children:s("oauth.callback.successDesc")})]}),e.jsxs(I,{className:"space-y-4",children:[r&&e.jsxs("div",{className:"bg-green-50 p-4 rounded-lg",children:[e.jsx("h4",{className:"font-semibold text-green-800",children:s("oauth.login.welcome",{name:r.name})}),e.jsx("p",{className:"text-sm text-green-600",children:r.email}),e.jsx("p",{className:"text-xs text-green-500 mt-1",children:s("oauth.login.role",{role:r.role})})]}),e.jsxs(z,{children:[e.jsx(H,{className:"h-4 w-4"}),e.jsx(F,{children:s("oauth.callback.redirecting")})]}),e.jsx("div",{className:"flex justify-center",children:e.jsx("div",{className:"animate-spin rounded-full h-6 w-6 border-b-2 border-green-600"})})]})]})}):g==="error"?e.jsx("div",{className:"min-h-screen flex items-center justify-center bg-gray-50",children:e.jsxs(C,{className:"w-full max-w-md",children:[e.jsxs(A,{className:"text-center",children:[e.jsxs(O,{className:"flex items-center justify-center gap-2 text-red-600",children:[e.jsx(re,{className:"h-6 w-6"}),s("oauth.callback.error")]}),e.jsx(E,{children:s("oauth.callback.errorDesc")})]}),e.jsxs(I,{className:"space-y-4",children:[e.jsxs(z,{variant:"destructive",children:[e.jsx(ie,{className:"h-4 w-4"}),e.jsx(F,{children:se(N)?s("auth.ssoSignupBlocked"):N})]}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx(M,{onClick:X,variant:"outline",className:"flex-1",children:s("oauth.callback.retry")}),e.jsx(M,{onClick:J,className:"flex-1",children:s("oauth.callback.login")})]}),e.jsx("p",{className:"text-xs text-gray-500 text-center",children:s("oauth.callback.supportMessage")})]})]})}):null};export{je as OAuth2Callback};

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.