(globalThis.TURBOPACK||(globalThis.TURBOPACK=[])).push(["object"==typeof document?document.currentScript:void 0,57222,e=>{"use strict";var r=e.i(43476),t=e.i(71645),o=e.i(18566),i=e.i(20755);function a(){let e=(0,o.useRouter)(),[a,s]=(0,t.useState)(null),[l,n]=(0,t.useState)("Completing authentication...");return(0,t.useEffect)(()=>{(async()=>{try{let{data:{session:r},error:t}=await i.supabase.auth.getSession();if(t){console.error("Session error:",t),s(t.message),setTimeout(()=>e.push("/"),3e3);return}if(r){console.log("Session found, checking referral...");let t=localStorage.getItem("tp_referrer_id");if(t&&t!==r.user.id)try{let e=localStorage.getItem("tp_referral_char_id");console.log("[Referral] Capturing from Callback:",t),localStorage.removeItem("tp_referrer_id"),localStorage.removeItem("tp_referral_char_id"),n("Finalizing referral..."),await fetch("/api/user/referred",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({referrerId:t,characterId:e})})}catch(e){console.error("Referral attribution failed:",e)}n("Success! Redirecting..."),e.push("/profile");return}n("Verifying session..."),await new Promise(e=>setTimeout(e,1e3));let{data:{session:o}}=await i.supabase.auth.getSession();if(o){console.log("Session found on retry, checking referral...");let r=localStorage.getItem("tp_referrer_id");if(r&&r!==o.user.id)try{let e=localStorage.getItem("tp_referral_char_id");localStorage.removeItem("tp_referrer_id"),localStorage.removeItem("tp_referral_char_id"),n("Finalizing referral..."),await fetch("/api/user/referred",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({referrerId:r,characterId:e})})}catch(e){console.error("Referral attribution failed:",e)}n("Success! Redirecting..."),e.push("/profile")}else console.log("No session found, redirecting to home"),n("No session found, redirecting..."),e.push("/")}catch(r){console.error("Unexpected error in auth callback:",r),s(r.message||"An unexpected error occurred"),setTimeout(()=>e.push("/"),3e3)}})()},[e]),(0,r.jsxs)("div",{style:{display:"flex",justifyContent:"center",alignItems:"center",height:"100vh",flexDirection:"column",gap:"20px"},children:[(0,r.jsx)("div",{className:"Login_loader__Rgn5k",style:{width:"48px",height:"48px"}}),a?(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)("p",{style:{color:"#ff6b6b",fontSize:"16px"},children:"Authentication Error"}),(0,r.jsx)("p",{style:{color:"#fff",fontSize:"14px",maxWidth:"400px",textAlign:"center"},children:a}),(0,r.jsx)("p",{style:{color:"#888",fontSize:"12px"},children:"Redirecting to home..."})]}):(0,r.jsx)("p",{style:{color:"#fff",fontSize:"16px"},children:l})]})}e.s(["default",()=>a])}]);