1import{r as m,j as t}from"./react-vendor-COfAJnF9.js";import{f as w,a as h,s as i,t as g,G as x,b as _,c as f,d as p}from"./index-Djvopu6Q.js";import{X as j,i as N}from"./icons-DL1w7JG0.js";import{b as E}from"./router-BVthG4yP.js";import"./supabase-DfuNjDQ7.js";import"./motion-Biay22SY.js";function G(){const s=E(),[n,b]=m.useState(null),r=w("/auth/callback");return m.useEffect(()=>{(async()=>{try{const{data:{session:e},error:l}=await i.auth.getSession();if(l)throw l;if(!e)throw new Error("No session found");const y=sessionStorage.getItem("pendingAction"),o=sessionStorage.getItem("returnPath")||"/",{data:a,error:c}=await i.from("users").upsert({id:e.user.id,google_id:e.user.user_metadata.sub,email:e.user.email??"",avatar_url:e.user.user_metadata.avatar_url??null,full_name:e.user.user_metadata.full_name??null,updated_at:new Date().toISOString()},{onConflict:"google_id"}).select("newsletter_opted_in").maybeSingle();if(c)throw c;if(e.user.email){const{error:d}=await i.from("subscribers").update({user_id:e.user.id}).eq("email",e.user.email).is("user_id",null);d&&console.error("Failed to link legacy subscriber row:",d)}const u=a==null?void 0:a.newsletter_opted_in;g(x.LOGIN,{method:"google",user_id:e.user.id}),_(e.user.id),f(p.USER_TYPE,"authenticated"),f(p.USER_ID,e.user.email||e.user.id),sessionStorage.removeItem("returnPath"),u==null?(g(x.SIGN_UP,{method:"google",user_id:e.user.id}),s("/newsletter-optin",{state:{returnTo:o},replace:!0})):s(o,{replace:!0})}catch(e){console.error("Auth callback error:",e),b(e instanceof Error?e.message:"Authentication failed")}})()},[s]),n?t.jsxs("div",{className:"min-h-screen bg-cream flex items-center justify-center p-4",children:[r&&t.jsx(h,{title:r.title,description:r.description,canonicalUrl:r.canonicalUrl,indexable:!1}),t.jsxs("div",{className:"bg-white rounded-lg shadow-lg p-8 max-w-md w-full",children:[t.jsx("div",{className:"flex items-center justify-between mb-4",children:t.jsxs("div",{className:"flex items-center gap-2",children:[t.jsx(j,{className:"w-6 h-6 text-red-600"}),t.jsx("h2",{className:"text-xl font-semibold text-charcoal",children:"Authentication Error"})]})}),t.jsx("p",{className:"text-gray-600 mb-6",children:n}),t.jsx("button",{onClick:()=>s("/",{replace:!0}),className:"w-full bg-burgundy text-white px-4 py-2 rounded-lg hover:bg-burgundy/90 transition-colors",children:"Return Home"})]})]}):t.jsxs("div",{className:"min-h-screen bg-cream flex items-center justify-center p-4",children:[r&&t.jsx(h,{title:r.title,description:r.description,canonicalUrl:r.canonicalUrl,indexable:!1}),t.jsxs("div",{className:"bg-white rounded-lg shadow-lg p-8 max-w-md w-full text-center",children:[t.jsx(N,{className:"w-12 h-12 text-burgundy mx-auto mb-4 animate-pulse"}),t.jsx("h2",{className:"text-xl font-semibold text-charcoal mb-2",children:"Completing sign in..."}),t.jsx("p",{className:"text-gray-600",children:"Please wait while we finish setting up your account."})]})]})}export{G 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.