1import{a as y,r as h,s as i,j as _,l as j}from"./index-oaoiWCW-.js";import{e as C}from"./oauthMetadata-CpmG_x8Z.js";import{getSignupContext as N,clearSignupContext as w}from"./signupTracking-VLkbTuKk.js";function R(){const c=y(),d=h.useRef(!1);return h.useEffect(()=>{const l=async r=>{var f;if(d.current||!(r!=null&&r.user))return;d.current=!0;const n=r.user,u=n.user_metadata||{},g=u.role;if(g==="doctor"){c("/medico/dashboard",{replace:!0});return}g!=="patient"&&await i.auth.updateUser({data:{role:"patient"}});const s=C(u),a=N(),b=((f=n.app_metadata)==null?void 0:f.provider)||(u==null?void 0:u.provider)||"email";let m=!1;try{const{data:o}=await i.from("patient_profiles").select("id, onboarding_completed, first_name, last_name, avatar_url, phone, terms_accepted, privacy_accepted, signup_source, signup_referrer, signup_utm_source, signup_utm_medium, signup_utm_campaign").eq("user_id",n.id).maybeSingle();o?o.onboarding_completed||(m=!0):(m=!0,await i.rpc("ensure_patient_profile"));const t=o||{},e={};!t.first_name&&s.first_name&&(e.first_name=s.first_name),!t.last_name&&s.last_name&&(e.last_name=s.last_name),!t.avatar_url&&s.avatar_url&&(e.avatar_url=s.avatar_url),t.signup_source||(e.signup_source=b==="google"?"google":"email"),!t.signup_referrer&&a.signup_referrer&&(e.signup_referrer=a.signup_referrer),!t.signup_utm_source&&a.signup_utm_source&&(e.signup_utm_source=a.signup_utm_source),!t.signup_utm_medium&&a.signup_utm_medium&&(e.signup_utm_medium=a.signup_utm_medium),!t.signup_utm_campaign&&a.signup_utm_campaign&&(e.signup_utm_campaign=a.signup_utm_campaign),Object.keys(e).length>0&&await i.from("patient_profiles").update(e).eq("user_id",n.id);const p={...t,...e},v=!p.phone||!p.terms_accepted||!p.privacy_accepted||!p.onboarding_completed;if(w(),v){c(`/auth/completa-profilo?next=${encodeURIComponent(m?"/account/benvenuto":"/account")}`,{replace:!0});return}}catch(o){console.error("[PatientAuthCallback] ensure profile failed",o)}c(m?"/account/benvenuto":"/account",{replace:!0})},{data:{subscription:x}}=i.auth.onAuthStateChange((r,n)=>l(n));return i.auth.getSession().then(({data:r})=>l(r.session)),()=>x.unsubscribe()},[c]),_.jsx("div",{className:"min-h-screen flex items-center justify-center bg-gradient-to-br from-background to-muted/30",children:_.jsxs("div",{className:"text-center space-y-3",children:[_.jsx(j,{className:"h-8 w-8 animate-spin mx-auto text-primary"}),_.jsx("p",{className:"text-sm text-muted-foreground",children:"Accesso in corsoâ¦"})]})})}export{R 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.