"use strict";(globalThis.webpackChunk_affine_web=globalThis.webpackChunk_affine_web||[]).push([[7644],{77644:(e,a,n)=>{n.r(a),n.d(a,{Component:()=>y,loader:()=>P});var r=n(36870),s=n(63234),i=n(94225),t=n(21817),o=n(47387),c=n(24312),l=n(10980),u=n(61569),m=n(86326),f=n(42277),h=n(4194),g=n(15010),p=n(67448),d=n(89679),w=n(69628),k=n(59481);let b=p.z.enum(["onboarding","setPassword","signIn","changePassword","signUp","changeEmail","confirm-change-email","subscription-redirect","verify-email"]),y=()=>{let e=(0,l.h1)(k.uR),a=(0,u.S)(e.session.account$),n=(0,c.s9)(),o=(0,l.h1)(k.BB).serverConfig,g=(0,u.S)(o.credentialsRequirement$.map(e=>e?.password)),{authType:p}=(0,f.g)(),[b]=(0,h.ok)(),{trigger:y}=(0,d.n)({mutation:t.JR}),{trigger:P}=(0,d.n)({mutation:t.$L}),{jumpToIndex:C}=(0,w.P)(),v=(0,m.useCallback)(async e=>{let a=await P({token:b.get("token")||"",email:e,callbackUrl:"/auth/confirm-change-email"}).catch(console.error);return a?.sendVerifyChangeEmail?s.me.success({title:n["com.arms.auth.sent.verify.email.hint"]()}):s.me.error({title:n["com.arms.auth.sent.change.email.fail"]()}),!!a?.sendVerifyChangeEmail},[b,P,n]),x=(0,m.useCallback)(async e=>{await y({token:b.get("token")||"",userId:b.get("userId")||"",newPassword:e})},[y,b]),E=(0,m.useCallback)(()=>{C(w.Q.REPLACE)},[C]);if(!g)return null;switch(p){case"onboarding":return a&&(0,r.jsx)(i.PW,{user:a,onOpenAffine:E});case"signUp":return a&&(0,r.jsx)(i.Cl,{user:a,passwordLimits:g,onSetPassword:x,onOpenAffine:E});case"signIn":return(0,r.jsx)(i.rr,{onOpenAffine:E});case"changePassword":return(0,r.jsx)(i.b,{passwordLimits:g,onSetPassword:x,onOpenAffine:E});case"setPassword":return(0,r.jsx)(i.TT,{passwordLimits:g,onSetPassword:x,onOpenAffine:E});case"changeEmail":return(0,r.jsx)(i.io,{onChangeEmail:v,onOpenAffine:E});case"confirm-change-email":case"verify-email":return(0,r.jsx)(i.zd,{onOpenAffine:E})}return null},P=async e=>{if(!e.params.authType||!b.safeParse(e.params.authType).success)return(0,g.V2)("/404");if("confirm-change-email"===e.params.authType){let a=new URL(e.request.url).searchParams,n=a.get("token")??"",r=decodeURIComponent(a.get("email")??""),s=await (0,o.GO)({query:t.cZ,variables:{token:n,email:r}}).catch(console.error);if(!s?.changeEmail)return(0,g.V2)("/expired")}else if("verify-email"===e.params.authType){let a=new URL(e.request.url).searchParams.get("token")??"",n=await (0,o.GO)({query:t.TY,variables:{token:a}}).catch(console.error);if(!n?.verifyEmail)return(0,g.V2)("/expired")}return null}}}]); //# sourceMappingURL=chunk.7644.2b13df2e.js.map