1import{c as V,u as K,a as Q,r as h,s as n,J as t,j as e,B as _,L as T,C as F}from"./index-ZkJ-s1rB.js";import{C as X,a as Y,b as ee,c as se,d as ae,L as y,I as v}from"./card-BuXUi2qO.js";import{T as re,a as te,b as R,c as Z}from"./tabs-DHiaIUJC.js";import{z as u}from"./index-3n2vhJSo.js";/** 2 * @license lucide-react v0.462.0 - ISC 3 * 4 * This source code is licensed under the ISC license. 5 * See the LICENSE file in the root directory of this source tree. 6 */const oe=V("Chrome",[["circle",{cx:"12",cy:"12",r:"10",key:"1mglay"}],["circle",{cx:"12",cy:"12",r:"4",key:"4exip2"}],["line",{x1:"21.17",x2:"12",y1:"8",y2:"8",key:"a0cw5f"}],["line",{x1:"3.95",x2:"8.54",y1:"6.06",y2:"14",key:"1kftof"}],["line",{x1:"10.88",x2:"15.46",y1:"21.94",y2:"14",key:"1ymyh8"}]]),z=u.string().min(8,"Password must be at least 8 characters").regex(/[A-Z]/,"Password must contain at least one uppercase letter").regex(/[a-z]/,"Password must contain at least one lowercase letter").regex(/[0-9]/,"Password must contain at least one number").regex(/[^A-Za-z0-9]/,"Password must contain at least one special character"),M=u.string().trim().email("Invalid email address").max(255,"Email must be less than 255 characters"),ie=u.string().trim().min(2,"Name must be at least 2 characters").max(100,"Name must be less than 100 characters").regex(/^[a-zA-Z\s'-]+$/,"Name can only contain letters, spaces, hyphens, and apostrophes"),ne=u.object({email:M,password:z,fullName:ie}),le=u.object({email:M,password:u.string().min(1,"Password is required")}),ce=["password","password123","12345678","qwerty","abc123","letmein","welcome","monkey","1234567890","password1"],de=m=>ce.some(p=>m.toLowerCase().includes(p)),ue=m=>{var p;try{return z.parse(m),de(m)?{valid:!1,error:"This password is too common. Please choose a stronger password."}:{valid:!0}}catch(l){return l instanceof u.ZodError?{valid:!1,error:(p=l.errors[0])==null?void 0:p.message}:{valid:!1,error:"Invalid password"}}},we=()=>{var G;const m=K(),p=Q(),[l,i]=h.useState(!1),[g,b]=h.useState(""),[w,S]=h.useState(""),[k,A]=h.useState(""),[c,j]=h.useState({}),[E,N]=h.useState(""),I=((G=p.state)==null?void 0:G.from)||"/";h.useEffect(()=>{let r=!0;n.auth.getSession().then(({data:{session:s}})=>{r&&s&&(s.provider_token&&setTimeout(()=>L(s),0),window.opener?(window.opener.postMessage({type:"auth-success"},window.location.origin),setTimeout(()=>window.close(),100)):m(I,{replace:!0}))});const{data:{subscription:a}}=n.auth.onAuthStateChange((s,o)=>{r&&(console.log("Auth event:",s),o&&(s==="SIGNED_IN"||s==="TOKEN_REFRESHED")&&(o.provider_token&&setTimeout(()=>L(o),0),s==="SIGNED_IN"&&(window.opener?(window.opener.postMessage({type:"auth-success"},window.location.origin),setTimeout(()=>window.close(),100)):m(I,{replace:!0}))),s==="SIGNED_OUT"&&console.log("User signed out"))});return()=>{r=!1,a.unsubscribe()}},[m,I]);const L=async r=>{try{const{error:a}=await n.from("profiles").update({google_access_token:r.provider_token,google_refresh_token:r.provider_refresh_token,google_token_expires_at:new Date(Date.now()+(r.expires_in||3600)*1e3).toISOString()}).eq("id",r.user.id);a?(console.error("Failed to store OAuth tokens:",a.message),t.error("Failed to store Google tokens")):t.success("Google account connected!")}catch(a){console.error("Error storing OAuth tokens:",(a==null?void 0:a.message)||"Unknown error")}},D=async r=>{try{const a=await fetch("https://api.ipify.org?format=json").catch(()=>null),s=a?(await a.json()).ip:"127.0.0.1",{data:o,error:f}=await n.functions.invoke("auth-rate-limit",{body:{action:r,ip:s}});if(f)throw f;return o}catch(a){return console.error("Rate limit check failed:",a),{allowed:!0}}},$=async r=>{r.preventDefault(),j({});try{ne.parse({email:g,password:w,fullName:k})}catch(a){if(a instanceof u.ZodError){const s={};a.errors.forEach(o=>{o.path[0]&&(s[o.path[0]]=o.message)}),j(s),t.error("Please fix the validation errors");return}}i(!0);try{const a=await D("signup");if(!a.allowed)throw new Error(a.message||"Too many signup attempts");const{error:s}=await n.auth.signUp({email:g,password:w,options:{emailRedirectTo:`${window.location.origin}/`,data:{full_name:k}}});if(s)throw s.message.includes("already registered")?new Error("This email is already registered. Please sign in instead."):s.message.includes("password")?new Error("Password does not meet requirements"):s;t.success("Account created! Please check your email to verify your account."),b(""),S(""),A(""),N("")}catch(a){console.error("Sign up error:",a),t.error(a.message||"Failed to sign up")}finally{i(!1)}},B=async r=>{r.preventDefault(),j({});try{le.parse({email:g,password:w})}catch(a){if(a instanceof u.ZodError){const s={};
6a.errors.forEach(o=>{o.path[0]&&(s[o.path[0]]=o.message)}),j(s),t.error("Please fix the validation errors");return}}i(!0);try{const a=await D("signin");if(!a.allowed)throw new Error(a.message||"Too many login attempts");const{error:s}=await n.auth.signInWithPassword({email:g,password:w});if(s)throw s.message.includes("Invalid login credentials")?new Error("Invalid email or password. Please check your credentials and try again."):s.message.includes("Email not confirmed")?new Error("Please verify your email before signing in. Check your inbox for the verification link."):s.message.includes("User not found")?new Error("No account found with this email. Please sign up first."):s;t.success("Signed in successfully!")}catch(a){console.error("Sign in error:",a),t.error(a.message||"Failed to sign in"),i(!1)}},H=async()=>{i(!0);const r=`${window.location.origin}/auth/callback`,a=window.self!==window.top;try{if(a){const{data:s,error:o}=await n.auth.signInWithOAuth({provider:"google",options:{redirectTo:r,scopes:"https://www.googleapis.com/auth/gmail.readonly https://www.googleapis.com/auth/gmail.send",queryParams:{access_type:"offline",prompt:"consent"},skipBrowserRedirect:!0}});if(o)throw o;if(!(s!=null&&s.url))throw new Error("Failed to get OAuth redirect URL");const f=window.open(s.url,"_blank","popup=yes,width=520,height=720");if(!f)throw new Error("Popup blocked. Please allow popups for this site.");t.info("Complete Google sign-in in the popup window");let x;const U=2*60*1e3,J=Date.now();x=setInterval(async()=>{if(Date.now()-J>U){clearInterval(x),t.error("Sign-in timed out. Please try again."),i(!1);return}const{data:d}=await n.auth.getSession();d.session&&(clearInterval(x),t.success("Signed in with Google"),i(!1))},1500);const P=async d=>{var q,O;if(d.source===f)if(clearInterval(x),window.removeEventListener("message",P),((q=d.data)==null?void 0:q.type)==="auth-success"){if(d.data.access_token&&d.data.refresh_token)try{await n.auth.setSession({access_token:d.data.access_token,refresh_token:d.data.refresh_token}),t.success("Signed in with Google"),i(!1);return}catch(C){console.error("Failed to set session:",C==null?void 0:C.message)}const{data:W}=await n.auth.getSession();W.session?t.success("Signed in with Google"):t.error("Authentication did not complete. Please try again."),i(!1)}else((O=d.data)==null?void 0:O.type)==="auth-error"&&(t.error(d.data.error||"Authentication failed"),i(!1))};window.addEventListener("message",P),setTimeout(()=>{clearInterval(x),window.removeEventListener("message",P),l&&(t.error("Sign-in timed out"),i(!1))},U)}else{const{error:s}=await n.auth.signInWithOAuth({provider:"google",options:{redirectTo:r,scopes:"https://www.googleapis.com/auth/gmail.readonly https://www.googleapis.com/auth/gmail.send",queryParams:{access_type:"offline",prompt:"consent"}}});if(s)throw s}}catch(s){console.error("Google sign-in error:",(s==null?void 0:s.message)||"Unknown error"),t.error(s.message||"Failed to sign in with Google"),i(!1)}};return e.jsx("div",{className:"min-h-screen flex items-center justify-center bg-background p-4",children:e.jsxs(X,{className:"w-full max-w-md",children:[e.jsxs(Y,{children:[e.jsx(ee,{className:"text-2xl font-medium",children:"Slick Inbox"}),e.jsx(se,{children:"Sign in to manage your inbox with ease"})]}),e.jsxs(ae,{children:[e.jsxs("div",{className:"mb-6",children:[e.jsxs(_,{onClick:H,disabled:l,variant:"outline",className:"w-full",children:[l?e.jsx(T,{className:"h-4 w-4 animate-spin"}):e.jsx(oe,{className:"h-4 w-4"}),"Continue with Google"]}),e.jsx("p",{className:"text-xs text-muted-foreground text-center mt-2",children:"Gmail integration enabled - we'll sync your inbox"})]}),e.jsxs("div",{className:"relative mb-6",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-card px-2 text-muted-foreground",children:"Or continue with email"})})]}),e.jsxs(re,{defaultValue:"signin",children:[e.jsxs(te,{className:"grid w-full grid-cols-2",children:[e.jsx(R,{value:"signin",children:"Sign In"}),e.jsx(R,{value:"signup",children:"Sign Up"})]}),e.jsx(Z,{value:"signin",children:e.jsxs("form",{onSubmit:B,className:"space-y-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(y,{htmlFor:"signin-email",children:"Email"}),e.jsx(v,{id:"signin-email",type:"email",placeholder:"[email protected]",value:g,onChange:r=>b(r.target.value),required:!0})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(y,{htmlFor:"signin-password",children:"Password"}),e.jsx(v,{id:"signin-password",type:"password",placeholder:"â¢â¢â¢â¢â¢â¢â¢â¢",value:w,onChange:r=>S(r.target.value),required:!0})]}),e.jsx(_,{type:"submit",className:"w-full",disabled:l,children:l?e.jsxs(e.Fragment,{children:[e.jsx(T,{className:"mr-2 h-4 w-4 animate-spin"}),"Signing in..."]}):"Sign In"})]})}),e.jsx(Z,{value:"signup",children:e.jsxs("form",{onSubmit:$,className:"space-y-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(y,{htmlFor:"signup-name",children:"Full Name"}),e.jsx(v,{id:"signup-name",type:"text",placeholder:"John Doe",value:k,onChange:r=>A(r.target.value),required:!0,className:c.fullName?"border-destructive":""}),c.fullName&&e.jsxs("p",{className:"text-xs text-destructive flex items-center gap-1",children:[e.jsx(F,{className:"h-3 w-3"}),c.fullName]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(y,{htmlFor:"signup-email",children:"Email"}),e.jsx(v,{id:"signup-email",type:"email",placeholder:"[email protected]",value:g,onChange:r=>b(r.target.value),required:!0,className:c.email?"border-destructive":""}),c.email&&e.jsxs("p",{className:"text-xs text-destructive flex items-center gap-1",children:[e.jsx(F,{className:"h-3 w-3"}),c.email]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(y,{htmlFor:"signup-password",children:"Password"}),e.jsx(v,{id:"signup-password",type:"password",placeholder:"â¢â¢â¢â¢â¢â¢â¢â¢",value:w,onChange:r=>{S(r.target.value);const a=ue(r.target.value);!a.valid&&r.target.value.length>
6=8?N(a.error||""):a.valid?N("Strong password â"):N("")},required:!0,className:c.password?"border-destructive":""}),c.password&&e.jsxs("p",{className:"text-xs text-destructive flex items-center gap-1",children:[e.jsx(F,{className:"h-3 w-3"}),c.password]}),E&&!c.password&&e.jsx("p",{className:`text-xs ${E.includes("â")?"text-green-600":"text-amber-600"}`,children:E}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"Must be 8+ characters with uppercase, lowercase, number, and special character"})]}),e.jsx(_,{type:"submit",className:"w-full",disabled:l,children:l?e.jsxs(e.Fragment,{children:[e.jsx(T,{className:"mr-2 h-4 w-4 animate-spin"}),"Creating account..."]}):"Sign Up"})]})})]})]})]})})};export{we 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.