1import{u as k,j as e}from"./vendor-query-bO2CTrcP.js";import{r as a}from"./vendor-react-DEEXKb7g.js";import{a as A,k as F,G as L,j as R,b as G,B as f,p as V}from"./index-U52Xbmw3.js";import{I as B}from"./use-blocks-BJ3DBq6g.js";import{I as q,a as U,b as d}from"./input-otp-CW_aCFDd.js";import{A as z,m as w}from"./vendor-motion-l_92Ldrf.js";import{L as b}from"./vendor-ui-DfIMOQp-.js";import{s as J,Z as M}from"./types-hapKmI0k.js";const W=()=>e.jsxs("svg",{viewBox:"0 0 24 24",width:"18",height:"18","aria-hidden":"true",children:[e.jsx("path",{fill:"#4285F4",d:"M22.56 12.25c0-.78-.07-1.53-.2-2.25H12v4.26h5.92c-.26 1.37-1.04 2.53-2.21 3.31v2.77h3.57c2.08-1.92 3.28-4.74 3.28-8.09z"}),e.jsx("path",{fill:"#34A853",d:"M12 23c2.97 0 5.46-.98 7.28-2.66l-3.57-2.77c-.98.66-2.23 1.06-3.71 1.06-2.86 0-5.29-1.93-6.16-4.53H2.18v2.84C3.99 20.53 7.7 23 12 23z"}),e.jsx("path",{fill:"#FBBC05",d:"M5.84 14.09c-.22-.66-.35-1.36-.35-2.09s.13-1.43.35-2.09V7.07H2.18C1.43 8.55 1 10.22 1 12s.43 3.45 1.18 4.93l3.66-2.84z"}),e.jsx("path",{fill:"#EA4335",d:"M12 5.38c1.62 0 3.06.56 4.21 1.64l3.15-3.15C17.45 2.09 14.97 1 12 1 7.7 1 3.99 3.47 2.18 7.07l3.66 2.84c.87-2.6 3.3-4.53 6.16-4.53z"})]}),H=J().email("Please enter a valid email address");function re(){const{t:v}=A(),[n,j]=a.useState(()=>localStorage.getItem("auth_email")||""),[g,u]=a.useState(()=>{const t=localStorage.getItem("auth_email"),r=localStorage.getItem("show_otp")==="true";return!!(t&&r)}),[h,m]=a.useState(()=>localStorage.getItem("auth_otp")||""),[l,o]=a.useState(!1),[p,x]=a.useState(()=>{const t=localStorage.getItem("auth_is_new_user");return t==="true"?!0:t==="false"?!1:null}),[Q,S]=a.useState(!1),{loginWithGoogle:N}=F(),_=L(),{toast:s}=R(),[,I]=G(),E=k(),y=new URLSearchParams(window.location.search);a.useEffect(()=>{n?localStorage.setItem("auth_email",n):localStorage.removeItem("auth_email")},[n]),a.useEffect(()=>{g?localStorage.setItem("show_otp","true"):localStorage.removeItem("show_otp")},[g]),a.useEffect(()=>{h?localStorage.setItem("auth_otp",h):localStorage.removeItem("auth_otp")},[h]),a.useEffect(()=>{p===!0?localStorage.setItem("auth_is_new_user","true"):p===!1?localStorage.setItem("auth_is_new_user","false"):localStorage.removeItem("auth_is_new_user")},[p]),a.useEffect(()=>{const t=()=>{const r=localStorage.getItem("auth_email"),i=localStorage.getItem("show_otp")==="true",c=localStorage.getItem("auth_otp");r&&i&&(u(!0),c&&m(c))};return window.addEventListener("focus",t),()=>{window.removeEventListener("focus",t)}},[]),a.useEffect(()=>{!y.has("otp")&&!localStorage.getItem("show_otp")&&(u(!1),localStorage.removeItem("show_otp"))},[]),a.useEffect(()=>{y.get("error")==="account_not_found"&&(x(!0),s({title:"Welcome!",description:"Create your account to continue"}),window.history.replaceState({},"","/auth"))},[]);const P=async t=>{if(t.preventDefault(),!l)try{o(!0);const r=H.parse(n),i=await fetch("/api/auth/check-contact",{method:"POST",headers:{"Content-Type":"application/json"},credentials:"include",body:JSON.stringify({email:r})});if(!i.ok){console.error("Check contact request failed:",i.status,i.statusText),s({title:"Error",description:"Failed to verify email. Please try again.",variant:"destructive"}),o(!1);return}const c=await i.json();console.log("[Email Submit] check-contact response:",c),x(!c.exists),console.log("[Email Submit] isNewUser set to:",!c.exists),await O(r)}catch(r){r instanceof M?s({title:"Invalid Email",description:r.errors[0].message,variant:"destructive"}):(console.error("Authentication failed:",r),s({title:"Authentication Error",description:r instanceof Error?r.message:"An error occurred",variant:"destructive"}))}finally{o(!1)}},O=async t=>{try{if(o(!0),!(await fetch("/api/auth/send-otp",{method:"POST",headers:{"Content-Type":"application/json"},credentials:"include",body:JSON.stringify({email:t,preferredCommunication:"email"})})).ok)throw new Error("Failed to send verification code");localStorage.setItem("show_otp","true"),u(!0)}catch(r){console.error("Error during authentication:",r),s({title:"Authentication Error",description:r instanceof Error?r.message:"An error occurred",variant:"destructive"})}finally{o(!1)}},T=async t=>
1{try{o(!0),console.log("Verifying OTP:",{email:n,code:t});const r=await fetch("/api/auth/verify-otp",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({code:t,email:n}),credentials:"include"}),i=await r.json();if(console.log("[OTP Verification] Response:",{ok:r.ok,data:i}),!r.ok){if(i.requiresTerms){s({title:"Terms Required",description:"Please accept the terms of service to create your account",variant:"destructive"}),o(!1);return}throw new Error(i.error||"Invalid verification code")}console.log("[OTP Verification] Success - redirecting to home page"),localStorage.removeItem("auth_email"),localStorage.removeItem("show_otp"),localStorage.removeItem("auth_otp"),localStorage.removeItem("auth_is_new_user"),console.log("Clearing all auth-related localStorage items and navigating to /"),await E.refetchQueries({queryKey:["/api/user"]}),console.log("[OTP Verification] User query refetched"),I("/",{replace:!0})}catch(r){console.error("OTP verification error:",r),s({title:"Verification Failed",description:r instanceof Error?r.message:"Please try again",variant:"destructive"}),m(""),o(!1)}},C=async()=>{try{await N()}catch(t){console.error("Google login error:",t),s({title:"Error",description:"Failed to start Google login",variant:"destructive"})}};return e.jsx("div",{className:"min-h-dvh flex items-center justify-center bg-background dark",children:e.jsxs("div",{className:"w-full max-w-md px-6",children:[e.jsx("div",{className:"flex justify-center mb-8",children:e.jsx("img",{src:"/assets/Skrollio.jpg",alt:"Skrollio Logo",width:1472,height:832,fetchPriority:"high",className:"w-full max-w-sm rounded-lg"})}),e.jsxs("div",{className:"text-center mb-8",children:[e.jsx("h1",{className:"text-2xl font-bold mb-2",children:"Welcome to Skrollio"}),e.jsx("p",{className:"text-muted-foreground text-sm",children:"Sign in or create an account to continue"})]}),e.jsx(z,{mode:"wait",children:g?e.jsxs(w.div,{initial:{opacity:0,y:20},animate:{opacity:1,y:0},exit:{opacity:0,y:-20},transition:{duration:.2},className:"space-y-4",children:[e.jsx("p",{className:"text-center text-sm text-muted-foreground mb-4",children:v("auth.enterVerificationCode")}),e.jsx("div",{className:"flex justify-center",children:e.jsx(q,{maxLength:6,value:h,onChange:t=>{m(t),t.length===6&&T(t)},disabled:l,children:e.jsxs(U,{className:"gap-2",children:[e.jsx(d,{index:0,className:"border-2 border-border bg-muted/50 text-foreground text-lg font-semibold w-12 h-14"}),e.jsx(d,{index:1,className:"border-2 border-border bg-muted/50 text-foreground text-lg font-semibold w-12 h-14"}),e.jsx(d,{index:2,className:"border-2 border-border bg-muted/50 text-foreground text-lg font-semibold w-12 h-14"}),e.jsx(d,{index:3,className:"border-2 border-border bg-muted/50 text-foreground text-lg font-semibold w-12 h-14"}),e.jsx(d,{index:4,className:"border-2 border-border bg-muted/50 text-foreground text-lg font-semibold w-12 h-14"}),e.jsx(d,{index:5,className:"border-2 border-border bg-muted/50 text-foreground text-lg font-semibold w-12 h-14"})]})})}),e.jsxs("div",{className:"flex flex-col gap-2 mt-4",children:[e.jsx(f,{variant:"outline",onClick:async()=>{try{if(o(!0),!(await fetch("/api/auth/send-otp",{method:"POST",headers:{"Content-Type":"application/json"},credentials:"include",body:JSON.stringify({email:n,preferredCommunication:"email"})})).ok)throw new Error("Failed to resend verification code");m(""),s({title:"Code Resent",description:"We've sent you a new verification code",variant:"default"})}catch(t){console.error("Error resending code:",t),s({title:"Error",description:t instanceof Error?t.message:"Failed to resend code",variant:"destructive"})}finally{o(!1)}},disabled:l,children:l?e.jsxs(e.Fragment,{children:[e.jsx(b,{className:"mr-2 h-4 w-4 animate-spin"}),"Sending..."]}):v("auth.resendCode")}),e.jsx(f,{variant:"ghost",onClick:()=>{u(!1),m(""),S(!1),x(null),localStorage.removeItem("show_otp")},disabled:l,children:"Use a different email"})]})]},"otp"):e.jsx(w.div,{initial:{opacity:0,y:20},animate:{opacity:1,y:0},exit:{opacity:0,y:-20},transition:{duration:.2},children:e.jsxs("div",{className:"space-y-4",children:[!_&&e.jsxs(e.Fragment,{children:[e.jsxs(f,{type:"button",variant:"secondary",className:"w-full h-12 flex items-center justify-center gap-2 font-medium shadow-[0_1px_0_#aaaaaa] active:shadow-none active:translate-y-1",onClick:C,disabled:l,children:[e.jsx(W,{}),"Continue with Google"]}),e.jsxs("div",{className:"relative",children:[e.jsx("div",{className:"absolute inset-0 flex items-center",children:e.jsx("span",{className:"w-full border-t"})}),e.jsx("div",{className:"relative flex justify-center text-xs uppercase",children:e.jsx("span",{className:"bg-background px-2 text-muted-foreground",children:"OR"})})]})]}),e.jsxs("form",{onSubmit:P,className:"space-y-4",children:[e.jsx(B,{id:"email",type:"email",value:n,onChange:t=>j(t.target.value),placeholder:"Enter your email",className:"h-11 border-2 border-border bg-muted/50 text-foreground placeholder:text-muted-foreground
1/70"}),e.jsx(f,{variant:"secondary",className:"w-full h-12 font-medium shadow-[0_1px_0_#aaaaaa] active:shadow-none active:translate-y-1",type:"submit",disabled:l||!n,children:l?e.jsxs(e.Fragment,{children:[e.jsx(b,{className:"mr-2 h-4 w-4 animate-spin"}),"Processing..."]}):"Continue with email"})]}),e.jsxs("p",{className:"text-center text-xs text-muted-foreground mt-2",children:["By continuing, you agree to our"," ",e.jsx("a",{href:"/terms",className:"underline hover:text-foreground",children:"Terms of Service"})," ","and"," ",e.jsx("a",{href:"/privacy",className:"underline hover:text-foreground",children:"Privacy Policy"})]})]})},"auth")}),!V()&&e.jsx("p",{className:"text-center text-xs text-muted-foreground mt-6",children:e.jsx("a",{href:"/archive",className:"underline hover:text-foreground",children:"Browse all Skrolls"})})]})})}export{re 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.