48ea61cdcc
- Product documentation in docs/products/ - Updated MEMORY.md with product info - quiXzoom Auth Core as AAMOS Identity product
3 lines
8.6 KiB
JavaScript
3 lines
8.6 KiB
JavaScript
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"}),e.jsx(x,{id:"email",type:"email",placeholder:s("auth.emailPlaceholder"),value:l,onChange:a=>{L(a.target.value),o.email&&c(t=>({...t,email:void 0}))},className:`pl-10 ${o.email?"border-destructive":""}`})]}),o.email&&e.jsx("p",{className:"text-xs text-destructive",children:o.email})]}),r!=="forgot"&&e.jsxs("div",{className:"space-y-2",children:[e.jsx(h,{htmlFor:"password",className:"text-sm text-muted-foreground",children:s("auth.password")}),e.jsxs("div",{className:"relative",children:[e.jsx(M,{className:"absolute left-3 top-1/2 -translate-y-1/2 w-4 h-4 text-muted-foreground"}),e.jsx(x,{id:"password",type:w?"text":"password",placeholder:"••••••••",value:d,onChange:a=>{R(a.target.value),o.password&&c(t=>({...t,password:void 0}))},className:`pl-10 pr-10 ${o.password?"border-destructive":""}`}),e.jsx("button",{type:"button",onClick:()=>$(!w),className:"absolute right-3 top-1/2 -translate-y-1/2 text-muted-foreground hover:text-foreground",children:w?e.jsx(q,{className:"w-4 h-4"}):e.jsx(z,{className:"w-4 h-4"})})]}),o.password&&e.jsx("p",{className:"text-xs text-destructive",children:o.password})]}),r==="signup"&&e.jsxs("div",{className:"space-y-2",children:[e.jsx(h,{htmlFor:"confirmPassword",className:"text-sm text-muted-foreground",children:s("auth.confirmPassword","Bekräfta lösenord")}),e.jsxs("div",{className:"relative",children:[e.jsx(M,{className:"absolute left-3 top-1/2 -translate-y-1/2 w-4 h-4 text-muted-foreground"}),e.jsx(x,{id:"confirmPassword",type:j?"text":"password",placeholder:"••••••••",value:P,onChange:a=>{S(a.target.value),o.confirmPassword&&c(t=>({...t,confirmPassword:void 0}))},className:`pl-10 pr-10 ${o.confirmPassword?"border-destructive":""}`}),e.jsx("button",{type:"button",onClick:()=>B(!j),className:"absolute right-3 top-1/2 -translate-y-1/2 text-muted-foreground hover:text-foreground",children:j?e.jsx(q,{className:"w-4 h-4"}):e.jsx(z,{className:"w-4 h-4"})})]}),o.confirmPassword&&e.jsx("p",{className:"text-xs text-destructive",children:o.confirmPassword})]}),r==="login"&&e.jsx("div",{className:"text-right",children:e.jsx("button",{type:"button",onClick:()=>m("forgot"),className:"text-xs text-primary hover:underline",children:"Glömt lösenord?"})}),e.jsx(N,{type:"submit",className:"w-full",disabled:C,children:C?s("auth.waiting"):r==="login"?s("auth.login"):r==="forgot"?"Skicka återställningslänk":s("auth.createAccount")})]}),e.jsx("div",{className:"mt-6 text-center space-y-2",children:r==="forgot"?e.jsx("button",{type:"button",onClick:()=>m("login"),className:"text-sm text-muted-foreground hover:text-foreground transition-colors",children:"← Tillbaka till inloggning"}):e.jsx("button",{type:"button",onClick:()=>m(r==="login"?"signup":"login"),className:"text-sm text-muted-foreground hover:text-foreground transition-colors",children:s(r==="login"?"auth.noAccount":"auth.hasAccount")})})]})}),e.jsx(_,{children:v&&e.jsx(y.div,{initial:{opacity:0},animate:{opacity:1},exit:{opacity:0},className:"fixed inset-0 z-50 flex items-center justify-center bg-black/60 backdrop-blur-sm p-4",children:e.jsxs(y.div,{initial:{scale:.9,opacity:0,y:20},animate:{scale:1,opacity:1,y:0},exit:{scale:.9,opacity:0,y:20},transition:{type:"spring",damping:25,stiffness:300},className:"bg-background rounded-2xl shadow-2xl max-w-sm w-full overflow-hidden",children:[e.jsxs("div",{className:"bg-gradient-to-br from-primary to-primary/80 p-6 text-center",children:[e.jsx("div",{className:"w-16 h-16 bg-white/20 rounded-2xl flex items-center justify-center mx-auto mb-4",children:e.jsx(I,{className:"w-8 h-8 text-white"})}),e.jsx("h2",{className:"text-xl font-bold text-white",children:s("auth.appPrompt.title","Fortsätt i appen?")}),e.jsx("p",{className:"text-white/80 text-sm mt-2",children:s("auth.appPrompt.subtitle","quiXzoom-appen ger en bättre upplevelse med notiser, kamera och GPS.")})]}),e.jsxs("div",{className:"p-6 space-y-3",children:[e.jsxs(N,{className:"w-full h-14 text-base font-semibold gap-3",onClick:()=>{const a=window.location.pathname+window.location.search;window.location.href=`quixzoom://auth/redirect?path=${encodeURIComponent(a)}`,setTimeout(()=>{window.location.href="/download-app"},2e3)},children:[e.jsx(I,{className:"w-5 h-5"}),s("auth.appPrompt.openApp","Öppna quiXzoom-appen")]}),e.jsxs(N,{variant:"outline",className:"w-full h-12 text-base gap-3",onClick:()=>{A(!1),f("/")},children:[e.jsx(Q,{className:"w-5 h-5"}),s("auth.appPrompt.continueWeb","Fortsätt i webbläsaren")]}),e.jsx("p",{className:"text-xs text-muted-foreground text-center pt-2",children:s("auth.appPrompt.hint","Du kan alltid ladda ner appen senare från din profil.")})]})]})})}),e.jsx(Y,{})]})};export{ne as default};
|
|
//# sourceMappingURL=Auth-BZtkFe2c.js.map
|