1import{r as a,j as e}from"./animation-CddyXVCz.js";import{c as K}from"./supabase-iKSPld20.js";import{b as $,g as M,c as O,d as V,e as W}from"./index-CGKNpi9E.js";import"./react-vendor-CbN3pvl2.js";import"./docgen-Bp8WKBAE.js";import"./query-DPqpbKNH.js";const q=new Set(["careerdiary://auth/callback","com.careerdiary.app://auth/callback","https://hiiacipnmifjekmpjjgcocikaecglmnl.chromiumapp.org/"]),F=s=>typeof s=="string"&&q.has(s),J=()=>{const{supabaseUrl:s,supabaseKey:o}=V();return!s||!o?null:K(s,o,{auth:{persistSession:!1,autoRefreshToken:!1,detectSessionInUrl:!1}})},Y=()=>{const[s]=$(),o=s.get("redirect_to"),P=s.get("email")??"",w=s.get("client"),h=s.get("state"),T=s.get("mode")==="signup"?"signUp":"signIn",[l,j]=a.useState(T),[x,U]=a.useState(P),[f,_]=a.useState(""),[v,S]=a.useState(!1),[N,d]=a.useState(null),[k,y]=a.useState(null),b=M(),[C,R]=a.useState(null),[D,L]=a.useState(!1),u=a.useRef(null),E=F(o),m=a.useMemo(J,[]),I=async t=>{if(!w||!h){const r=new URLSearchParams({access_token:t.access_token,refresh_token:t.refresh_token,expires_in:String(t.expires_in??3600),token_type:t.token_type??"bearer",provider:"email"});window.location.href=`${o}#${r.toString()}`;return}const n=await fetch("/api/auth/native/issue",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({session:t,client:w,state:h})});if(!n.ok)throw new Error("Could not complete sign-in. Please try again.");const{code:g}=await n.json(),p=new URLSearchParams({code:g,state:h,provider:"email"});window.location.href=`${o}?${p.toString()}`},A=async t=>{var g,p;if(t.preventDefault(),!E||!m)return;d(null),y(null);const n=W({siteKeyConfigured:!!b,token:C,unavailable:D});if(n.blocked){d(n.message);return}S(!0);try{const r=C??void 0;if(l==="signIn"){const{data:i,error:c}=await m.auth.signInWithPassword({email:x,password:f,options:{...r?{captchaToken:r}:{}}});if(c)throw c;if(!i.session)throw new Error("No session returned. Please try again.");await I(i.session)}else{const{data:i,error:c}=await m.auth.signUp({email:x,password:f,options:{...r?{captchaToken:r}:{},data:{signup_intent:"trial"}}});if(c)throw c;i.session?await I(i.session):(y("Check your email to confirm your account, then return here to sign in."),j("signIn"),(g=u.current)==null||g.reset())}}catch(r){const i=r instanceof Error?r.message:"Sign in failed. Please try again.";d(i),(p=u.current)==null||p.reset()}finally{S(!1)}};return E?m?e.jsx("div",{className:"min-h-screen flex items-center justify-center bg-gray-50 px-4 py-8",children:e.jsxs("div",{className:"max-w-sm w-full rounded-2xl border border-gray-200 bg-white p-6 shadow-sm",children:[e.jsx("h1",{className:"text-xl font-bold text-gray-900 mb-1",children:l==="signIn"?"Sign in to CareerDiary":"Create your account"}),e.jsx("p",{className:"text-sm text-gray-500 mb-5",children:l==="signIn"?"Continue to the CareerDiary app.":"Sign up to continue to the CareerDiary app."}),e.jsxs("form",{onSubmit:A,className:"space-y-4",children:[e.jsxs("div",{className:"space-y-1.5",children:[e.jsx("label",{htmlFor:"native-email",className:"text-xs font-semibold text-gray-500 uppercase tracking-wide",children:"Email"}),e.jsx("input",{id:"native-email",type:"email",autoComplete:"email",required:!0,value:x,onChange:t=>U(t.target.value),placeholder:"[email protected]",className:"w-full h-11 rounded-lg border border-gray-200 bg-gray-50 px-3 text-sm focus:outline-none focus:ring-2 focus:ring-emerald-500/30 focus:bg-white"})]}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsx("label",{htmlFor:"native-password",className:"text-xs font-semibold text-gray-500 uppercase tracking-wide",children:"Password"}),e.jsx("input",{id:"native-password",type:"password",autoComplete:l==="signUp"?"new-password":"current-password",required:!0,minLength:6,value:f,onChange:t=>_(t.target.value),placeholder:"â¢â¢â¢â¢â¢â¢â¢â¢",className:"w-full h-11 rounded-lg border border-gray-200 bg-gray-50 px-3 text-sm focus:outline-none focus:ring-2 focus:ring-emerald-500/30 focus:bg-white"})]}),b&&e.jsx(O,{onUnavailable:()=>L(!0),ref:u,siteKey:b,onToken:R,className:"flex justify-center"}),k&&e.jsx("p",{className:"text-sm text-emerald-700 bg-emerald-50 border border-emerald-200 rounded-lg px-3 py-2",children:k}),N&&e.jsx("p",{className:"text-sm text-red-600 bg-red-50 border border-red-200 rounded-lg px-3 py-2",children:N}),e.jsx("button",{type:"submit",disabled:v,className:"w-full h-11 rounded-lg bg-emerald-600 text-white text-sm font-semibold hover:bg-emerald-700 disabled:opacity-50 transition-colors",children:v?"Please waitâ¦":l==="sign
1In"?"Sign In":"Create Account"})]}),e.jsx("button",{type:"button",onClick:()=>{var t;j(n=>n==="signIn"?"signUp":"signIn"),d(null),y(null),(t=u.current)==null||t.reset()},className:"mt-4 w-full text-center text-sm text-emerald-700 hover:underline",children:l==="signIn"?"Don't have an account? Sign Up":"Already have an account? Sign In"})]})}):e.jsx("div",{className:"min-h-screen flex items-center justify-center bg-gray-50 px-4",children:e.jsxs("div",{className:"max-w-sm w-full rounded-2xl border border-gray-200 bg-white p-6 text-center shadow-sm",children:[e.jsx("h1",{className:"text-lg font-bold text-gray-900 mb-2",children:"Sign-in unavailable"}),e.jsx("p",{className:"text-sm text-gray-600",children:"Authentication isn't configured. Please try again later."})]})}):e.jsx("div",{className:"min-h-screen flex items-center justify-center bg-gray-50 px-4",children:e.jsxs("div",{className:"max-w-sm w-full rounded-2xl border border-gray-200 bg-white p-6 text-center shadow-sm",children:[e.jsx("h1",{className:"text-lg font-bold text-gray-900 mb-2",children:"Can't open this page directly"}),e.jsx("p",{className:"text-sm text-gray-600",children:"This sign-in page is opened by the CareerDiary app. Please launch it from the app's âContinue with Emailâ button."})]})})};export{Y as NativeAuthPage,Y 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.