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

//# sourceMappingURL=app_auth_callback_page_tsx_36a2f54a._.js.map