Files
boc/landvex-site/assets/Auth-BZtkFe2c.js
T

3 lines
8.6 KiB
JavaScript
Raw Normal View History

import{u as V,o as X,a as J,r as i,s as F,j as e,p as y,q as h,U as H,I as x,t as M,v as N,G as Q,B as Y,w as n}from"./index-CZD3_4lD.js";import{M as Z}from"./mail-C8_RqWpe.js";import{E as q}from"./eye-off-CHF4QKq3.js";import{E as z}from"./eye-IKrhkOAd.js";import{A as _}from"./index-DXB3_sFe.js";import{S as I}from"./smartphone-Ca6TX_3a.js";const ne=()=>{const f=V(),{user:b,signIn:O,signUp:T,isLoading:g}=X(),{t:s}=J(),[r,m]=i.useState("login"),[l,L]=i.useState(""),[d,R]=i.useState(""),[P,S]=i.useState(""),[k,W]=i.useState(""),[w,$]=i.useState(!1),[j,B]=i.useState(!1),[C,u]=i.useState(!1),[v,A]=i.useState(!1),[ee,G]=i.useState(!1),[o,c]=i.useState({}),E=F().email(s("auth.invalidEmail")),U=F().min(6,s("auth.passwordMinLength"));i.useEffect(()=>{if(b&&!g&&!v){const a=/(WebView|wv|iPhone.*Mobile.*Safari)/i.test(navigator.userAgent)&&!/(Chrome|CriOS|Firefox|FxiOS)/i.test(navigator.userAgent);/iPhone|iPad|iPod|Android/i.test(navigator.userAgent)&&!a?(A(!0),G(!0)):f("/")}},[b,g,f,v]),i.useEffect(()=>{S(""),c({})},[r]);const D=()=>{const a={},t=E.safeParse(l);t.success||(a.email=t.error.errors[0].message);const p=U.safeParse(d);return p.success||(a.password=p.error.errors[0].message),r==="signup"&&d!==P&&(a.confirmPassword=s("auth.passwordMismatch","Lösenorden matchar inte")),c(a),Object.keys(a).length===0},K=async a=>{if(a.preventDefault(),r==="forgot"){if(!E.safeParse(l).success){c({email:s("auth.invalidEmail")});return}u(!0);try{const t=await fetch("https://api.quixzoom.com/api/qz/auth/forgot-password",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({email:l})});if(t.ok)n.success("Instruktioner för lösenordsåterställning har skickats till din e-post"),m("login");else{const p=await t.json().catch(()=>({}));n.error(p.error||"Kunde inte skicka återställningslänk")}}catch{n.error("Kunde inte ansluta till servern")}finally{u(!1)}return}if(D()){u(!0);try{if(r==="login"){const{error:t}=await O(l,d);t?n.error(t.message.includes("Invalid login credentials")?s("auth.invalidCredentials"):t.message):n.success(s("auth.loginSuccess"))}else{const{error:t}=await T(l,d,k);t?n.error(t.message.includes("already registered")?s("auth.emailAlreadyRegistered"):t.message):n.success(s("auth.signupSuccess"))}}catch{n.error(s("auth.somethingWentWrong"))}finally{u(!1)}}};return g?e.jsx("div",{className:"min-h-screen bg-background flex items-center justify-center",children:e.jsx("div",{className:"animate-pulse text-muted-foreground",children:s("common.loading")})}):e.jsxs("div",{className:"min-h-screen bg-background flex flex-col",children:[e.jsxs("div",{className:"bg-gradient-to-br from-primary to-primary/80 text-primary-foreground p-6 pt-[calc(env(safe-area-inset-top)+1.5rem)]",children:[e.jsx("h1",{className:"text-2xl font-bold",children:r==="login"?s("auth.login"):r==="signup"?s("auth.signup"):"Återställ lösenord"}),e.jsx("p",{className:"text-primary-foreground/70 text-sm mt-1",children:r==="login"?s("auth.loginSubtitle"):r==="signup"?s("auth.signupSubtitle"):"Ange din e-postadress så skickar vi en återställningslänk"})]}),e.jsx("main",{className:"flex-1 flex items-center justify-center px-4 pb-20",children:e.jsxs(y.div,{initial:{opacity:0,y:20},animate:{opacity:1,y:0},transition:{duration:.4},className:"w-full max-w-sm",children:[e.jsxs("form",{onSubmit:K,className:"space-y-4",children:[r==="signup"&&e.jsxs("div",{className:"space-y-2",children:[e.jsx(h,{htmlFor:"displayName",className:"text-sm text-muted-foreground",children:s("auth.displayName")}),e.jsxs("div",{className:"relative",children:[e.jsx(H,{className:"absolute left-3 top-1/2 -translate-y-1/2 w-4 h-4 text-muted-foreground"}),e.jsx(x,{id:"displayName",type:"text",placeholder:s("auth.displayNamePlaceholder"),value:k,onChange:a=>W(a.target.value),className:"pl-10"})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(h,{htmlFor:"email",className:"text-sm text-muted-foreground",children:s("auth.email")}),e.jsxs("div",{className:"relative",children:[e.jsx(Z,{className:"absolute left-3 top-1/2 -translate-y-1/2 w-4 h-4 text-muted-foreground"}),
//# sourceMappingURL=Auth-BZtkFe2c.js.map