1import{bw as S,bg as w,by as i,d1 as x,d2 as C,cV as I,d4 as k,gm as m,cP as y,d3 as P,d5 as v}from"./index-Cwb4f_ZN.js";import{u as D,a as U}from"./index.esm-wfYYG3ip.js";import"./index.esm-D2usRJJk.js";function T(){const[,n]=S(),d=D(),{user:z}=U(),[f,u]=w.useState(null);return w.useEffect(()=>{(async()=>{const p=new URLSearchParams(window.location.search),l=p.get("token"),c=p.get("stytch_token_type");if(!l){u("No authentication token found");return}try{if(c==="magic_links"||c==="login")await d.magicLinks.authenticate(l,{session_duration_minutes:3360});else if(c==="impersonation")await d.impersonation.authenticate({impersonation_token:l});else if(c==="oauth")await d.oauth.authenticate(l,{session_duration_minutes:3360});else{u(`Unsupported token type: ${c}`);return}console.log("[Candidate Callback] Stytch authentication complete, checking profile status..."),await new Promise(s=>setTimeout(s,100));const o=await fetch("/api/auth/stytch/candidate-profile-status",{credentials:"include",headers:{"Content-Type":"application/json"}});if(!o.ok){const s=await o.text();throw console.error("[Candidate Callback] Profile check failed:",o.status,s),new Error(`Failed to check profile status: ${o.status}`)}const j=await o.json(),{redirectTarget:g,wizardSession:e}=j.data||{},a=C();let t=null;if(a!=null&&a.jobId||a!=null&&a.jobSlug?t={...e,...a,cvParsedData:a.cvParsedData||(e==null?void 0:e.cvParsedData),wizardSessionId:a.wizardSessionId||(e==null?void 0:e.wizardSessionId)}:e&&(t=e),console.log("[Candidate Callback] Profile status check complete",{redirectTarget:g,hasLocalWizardSession:!!a,hasServerWizardSession:!!e,wizardJobId:t==null?void 0:t.jobId,wizardJobSlug:t==null?void 0:t.jobSlug}),await I.refetchQueries({queryKey:["/api/auth/user"]}),t){const s=`wizard-state-${t.jobId}`,r={step:"signup",wizardSessionId:t.wizardSessionId,cvData:t.cvParsedData?{fileName:"oauth-restored.pdf",parsedData:{name:`${t.cvParsedData.firstName||""} ${t.cvParsedData.lastName||""}`.trim(),email:t.cvParsedData.email,phone:t.cvParsedData.phone}}:void 0,oauthCompleted:!0,mockInterviewRequired:!1};sessionStorage.setItem(s,JSON.stringify(r)),sessionStorage.setItem("oauth_wizard_return",JSON.stringify({jobId:t.jobId,jobSlug:t.jobSlug,wizardSessionId:t.wizardSessionId,cvParsedData:t.cvParsedData,timestamp:Date.now()})),k(),m();const h=t.jobSlug?`/jobs/${t.jobSlug}`:`/jobs/${t.jobId}`,b=y(h);console.log("[Candidate Callback] OAuth wizard return, redirecting to:",h),b.startsWith("http")?window.location.href=b:n(h)}else{m();const s=P();if(s){k(),console.log("[Candidate Callback] Restoring return URL:",s);const r=y(s);r.startsWith("http")?window.location.href=r:n(s)}else{const r=g||v("candidate");r.startsWith("http")?window.location.href=r:n(r)}}}catch(o){console.error("[Candidate Callback] Authentication failed:",o),m(),u(o instanceof Error?o.message:"Authentication failed")}})()},[d,n]),f?i.jsx("div",{className:"bg-muted flex min-h-svh flex-col items-center justify-center p-6",children:i.jsxs("div",{className:"w-full max-w-md bg-background p-8 rounded-lg shadow-lg text-center",children:[i.jsx("h1",{className:"text-2xl font-bold text-destructive mb-4",children:"Authentication Error"}),i.jsx("p",{className:"text-muted-foreground mb-6",children:f}),i.jsx("button",{onClick:()=>n("/candidate-auth"),className:"px-4 py-2 bg-primary text-primary-foreground rounded-md hover:bg-primary/90","data-testid":"button-retry-auth",children:"Try Again"})]})}):i.jsx(x,{message:"Completing authentication..."})}export{T as default}; 2//# sourceMappingURL=candidate-callback-GFtYO5t_.js.map
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.