UNPKG

decocms

Version:

Deco CMS — Self-hostable MCP Gateway for managing AI connections and tools

2 lines (1 loc) • 21.8 kB
import{a as $,c as ce,m as S,j as t,a3 as Ke,a4 as Ge,a5 as ke,r as N,e as te,E as M,B as se,I as ae,b as Fe,h as Ye}from"./index-DoEtSiIe.js";import{i as Je}from"./Fingerprint04-DlIWxzRc.js";import{e as Qe}from"./backoff-CrEUbyZT.js";import{d as Xe}from"./delay-CnY5UFtP.js";class Le extends Error{constructor(e,r){super(`Retrying exceeded the maxAttempts (${r}).`),this.name="RetryError",this.cause=e}}async function Ze(n,e){const{multiplier:r=2,maxTimeout:l=6e4,maxAttempts:g=5,minTimeout:m=1e3,jitter:i=1,isRetriable:u=()=>!0,signal:d}=e??{};if(!Number.isInteger(g)||g<1)throw new RangeError(`Cannot retry as 'maxAttempts' must be a positive integer: current value is ${g}`);if(!Number.isFinite(r)||r<1)throw new RangeError(`Cannot retry as 'multiplier' must be a finite number >= 1: current value is ${r}`);if(Number.isNaN(l)||l<=0)throw new RangeError(`Cannot retry as 'maxTimeout' must be a positive number: current value is ${l}`);if(Number.isNaN(m)||m<0)throw new RangeError(`Cannot retry as 'minTimeout' must be >= 0: current value is ${m}`);if(m>l)throw new RangeError(`Cannot retry as 'minTimeout' must be <= 'maxTimeout': current values 'minTimeout=${m}', 'maxTimeout=${l}'`);if(Number.isNaN(i)||i<0||i>1)throw new RangeError(`Cannot retry as 'jitter' must be between 0 and 1: current value is ${i}`);let b=0;for(;;){d?.throwIfAborted();try{return await n()}catch(f){if(!u(f))throw f;if(b+1>=g)throw new Le(f,g);const v=Qe(l,m,b,r,i);await Xe(v,d?{signal:d}:void 0)}b++}}const Oe={submitEmailPassword:({mode:n,email:e,password:r,name:l})=>n==="sign_up"?$.signUp.email({email:e,password:r,name:l||""}):$.signIn.email({email:e,password:r}),requestPasswordReset:({email:n,redirectTo:e})=>$.requestPasswordReset({email:n,redirectTo:e}),sendOtp:({email:n})=>$.emailOtp.sendVerificationOtp({email:n,type:"sign-in"}),submitOtp:({email:n,otp:e})=>$.signIn.emailOtp({email:n,otp:e}),socialSignIn:({provider:n,callbackURL:e})=>$.signIn.social({provider:n,callbackURL:e}),ssoSignIn:({providerId:n,callbackURL:e})=>$.signIn.sso({providerId:n,callbackURL:e}),passkeySignIn:()=>$.signIn.passkey(),onAuthenticated:n=>{window.location.href=n}};function et(n){const e=ce.c(25);let r,l,g,m,i,u,d,b;e[0]!==n?({length:g,className:r,containerClassName:l,slotClassName:i,pattern:u,inputMode:d,autoComplete:b,...m}=n,e[0]=n,e[1]=r,e[2]=l,e[3]=g,e[4]=m,e[5]=i,e[6]=u,e[7]=d,e[8]=b):(r=e[1],l=e[2],g=e[3],m=e[4],i=e[5],u=e[6],d=e[7],b=e[8]);const f=u===void 0?Ge:u,v=d===void 0?"numeric":d,p=b===void 0?"one-time-code":b;let h;e[9]!==l?(h=S("flex items-center gap-2 has-[:disabled]:opacity-50",l),e[9]=l,e[10]=h):h=e[10];let A;e[11]!==r?(A=S("disabled:cursor-not-allowed",r),e[11]=r,e[12]=A):A=e[12];let y;e[13]!==m||e[14]!==i?(y=x=>{const{slots:j}=x;return t.jsx(t.Fragment,{children:j.map((D,q)=>t.jsx(tt,{...D,invalid:m["aria-invalid"]===!0,className:i},q))})},e[13]=m,e[14]=i,e[15]=y):y=e[15];let w;return e[16]!==p||e[17]!==v||e[18]!==g||e[19]!==f||e[20]!==m||e[21]!==h||e[22]!==A||e[23]!==y?(w=t.jsx(Ke,{"data-slot":"input-otp",maxLength:g,pattern:f,inputMode:v,autoComplete:p,containerClassName:h,className:A,render:y,...m}),e[16]=p,e[17]=v,e[18]=g,e[19]=f,e[20]=m,e[21]=h,e[22]=A,e[23]=y,e[24]=w):w=e[24],w}function tt(n){const e=ce.c(13),{char:r,placeholderChar:l,hasFakeCaret:g,isActive:m,invalid:i,className:u}=n,d=m||void 0,b=i&&"bg-destructive/10 shadow-[inset_0_0_0_1px_var(--destructive)]";let f;e[0]!==u||e[1]!==b?(f=S("relative flex h-12 w-10 flex-1 items-center justify-center text-xl font-medium tabular-nums text-foreground transition-[background-color,box-shadow]","rounded-[var(--studio-control-radius,var(--radius-lg))] bg-[var(--studio-input-background)] shadow-edge","data-active:shadow-[inset_0_0_0_2px_var(--ring)]",b,u),e[0]=u,e[1]=b,e[2]=f):f=e[2];let v;e[3]!==r||e[4]!==l?(v=r??t.jsx("span",{className:"text-subtle-foreground",children:l}),e[3]=r,e[4]=l,e[5]=v):v=e[5];let p;e[6]!==g?(p=g&&t.jsx("div",{className:"pointer-events-none absolute inset-0 flex items-center justify-center",children:t.jsx("div",{className:"h-5 w-px animate-pulse bg-foreground"})}),e[6]=g,e[7]=p):p=e[7];let h;return e[8]!==d||e[9]!==f||e[10]!==v||e[11]!==p?(h=t.jsxs("div",{"data-slot":"input-otp-slot","data-active":d,className:f,children:[v,p]}),e[8]=d,e[9]=f,e[10]=v,e[11]=p,e[12]=h):h=e[12],h}const de="font-medium text-[#8CAA25] hover:underline disabled:opacity-50",st={signUpFailed:"Sign up failed",signInFailed:"Sign in failed",authenticationFailed:"Authentication failed",resetEmailFailed:"Failed to send reset email",otpSendFailed:"Failed to send code",invalidCode:"Invalid code",invalidEmail:"Invalid email address",invalidEmailOrPassword:"Invalid email or password. Please try again.",accountExists:"An account with this email already exists. Try signing in instead.",networkError:"Network error. Please check your connection and try again.",tooManyAttempts:"Too many attempts. Please wait a moment and try again.",invalidOrExpiredCode:"Invalid or expired code. Please try again.",genericError:"An error occurred. Please try again.",resetPasswordTitle:"Reset your password",verificationCodeTitle:"Enter verification code",welcomeTitle:"Welcome to deco",resetPasswordSubtitle:"We'll send you a reset link",codeSentTo:n=>`Code sent to ${n}`,defaultSubtitle:"Sign in or create a new account",resetEmailSent:"Check your email for a password reset link.",continueWith:n=>`Continue with ${n}`,divider:"or",emailLabel:"Email",emailPlaceholder:"Email address",sending:"Sending...",sendCode:"Send code",verificationCodeLabel:"Verification code",verifying:"Verifying...",useDifferentEmail:"Use a different email",sendResetLink:"Send reset link",nameLabel:"Name",namePlaceholder:"Your name",passwordLabel:"Password",forgotPassword:"Forgot password?",creatingAccount:"Creating account...",signingIn:"Signing in...",continue:"Continue",backToSignIn:"Back to sign in",signInWithPassword:"Sign in with password instead",alreadyHaveAccount:"Already have an account? ",dontHaveAccount:"Don't have an account? ",signIn:"Sign in",signUp:"Sign up",signInWithEmailCode:"Sign in with email code",signInWithPasskey:"Sign in with a passkey"};function at({redirectUrl:n,callbackUrl:e="/",title:r,subtitle:l,brand:g,copy:m,variant:i="default",allowedSocialProviders:u,allowPassword:d=!0,onAuthEvent:b,actions:f}){const{emailAndPassword:v,resetPassword:p,emailOtp:h,passkey:A,socialProviders:y}=ke(),w={...Oe,...f},x=s=>{try{b?.(s)}catch{}},j=i==="compact",D=u?y.providers.filter(s=>u.includes(s.name)):y.providers,q=y.enabled&&D.length>0,me=v.enabled&&(d||!h.enabled&&!q),_=y.enabled&&y.providers.length>0&&!q&&!h.enabled&&!me?y.providers:D,T=y.enabled&&_.length>0,k=v.enabled&&(d||!h.enabled&&!T),F=A.enabled&&d&&typeof globalThis.PublicKeyCredential<"u",W=T||F,[c,ne]=N.useState(""),[ie,Re]=N.useState(""),[ue,be]=N.useState(""),[ge,re]=N.useState(""),[Y,he]=N.useState(!1),[pe,$e]=N.useState(()=>h.enabled?"emailOtp":globalThis.localStorage?.getItem("hasLoggedIn")!=="true"?"signUp":"signIn"),[C,B]=N.useState(""),[ve,we]=N.useState(!1),[Me,oe]=N.useState(null),a={...st,...m},z=N.useId(),V=`${z}-email`,H=`${z}-email-error`,ye=`${z}-name`,Ee=`${z}-password`,Se=`${z}-otp`,je=`${z}-otp-status`,I=pe==="signUp",R=pe==="forgotPassword",L=pe==="emailOtp",J=te({mutationFn:async({email:s,password:o,name:O})=>{try{const G=await w.submitEmailPassword({mode:I?"sign_up":"sign_in",email:s,password:o,name:O});if(G.error)throw new Error(G.error.message||(I?a.signUpFailed:a.signInFailed));return G}catch(G){throw G instanceof Error?G:new Error(a.authenticationFailed)}},onMutate:()=>{x({type:"started",method:"email_password",mode:I?"sign_up":"sign_in"})},onSuccess:()=>{x({type:"succeeded",method:"email_password",mode:I?"sign_up":"sign_in"}),globalThis.localStorage?.setItem("hasLoggedIn","true"),w.onAuthenticated(n??e)},onError:s=>{x({type:"failed",method:"email_password",mode:I?"sign_up":"sign_in",stage:"authenticate",error:s instanceof Error?s.message:String(s)}),M(I?"user_signup_failed":"user_signin_failed",{error:s instanceof Error?s.message:String(s)})}}),Q=te({mutationFn:async({email:s})=>{const o=await w.requestPasswordReset({email:s,redirectTo:"/reset-password"});if(o.error)throw new Error(o.error.message||a.resetEmailFailed);return o},onSuccess:()=>{M("password_reset_requested"),we(!0)},onError:s=>{M("password_reset_request_failed",{error:s instanceof Error?s.message:String(s)})}}),U=te({mutationFn:async({email:s})=>{const o=await w.sendOtp({email:s});if(o.error)throw new Error(o.error.message||a.otpSendFailed);return o},onMutate:()=>{x({type:"started",method:"email_otp"})},onSuccess:()=>{x({type:"otp_sent",method:"email_otp"}),M("email_otp_sent"),he(!0)},onError:s=>{x({type:"failed",method:"email_otp",stage:"send_otp",error:s instanceof Error?s.message:String(s)}),M("email_otp_send_failed",{error:s instanceof Error?s.message:String(s)})}}),P=te({mutationFn:async({email:s,otp:o})=>{const O=await w.submitOtp({email:s,otp:o});if(O.error)throw new Error(O.error.message||a.invalidCode);return O},onMutate:()=>{x({type:"otp_submitted",method:"email_otp"})},onSuccess:()=>{x({type:"succeeded",method:"email_otp"}),globalThis.localStorage?.setItem("hasLoggedIn","true"),w.onAuthenticated(n??e)},onError:s=>{re(""),x({type:"failed",method:"email_otp",stage:"verify_otp",error:s instanceof Error?s.message:String(s)}),M("email_otp_verify_failed",{error:s instanceof Error?s.message:String(s)})}}),X=te({mutationFn:async()=>{const s=await w.passkeySignIn();if(s.error){if(s.error.code==="AUTH_CANCELLED")return{cancelled:!0};throw new Error(s.error.message||a.authenticationFailed)}return{cancelled:!1}},onMutate:()=>{x({type:"started",method:"passkey"})},onSuccess:({cancelled:s})=>{s||(x({type:"succeeded",method:"passkey"}),globalThis.localStorage?.setItem("hasLoggedIn","true"),w.onAuthenticated(n??e))},onError:s=>{x({type:"failed",method:"passkey",stage:"authenticate",error:s.message}),M("passkey_signin_failed",{error:s.message})}}),le=s=>/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(s),fe=()=>{c.trim()&&!le(c)&&B(a.invalidEmail)},We=s=>{if(s.preventDefault(),!le(c)){B(a.invalidEmail),x({type:"failed",method:"email_password",mode:I?"sign_up":"sign_in",stage:"validation",error:"invalid_email"});return}J.mutate({email:c,password:ie,name:ue})},Ue=s=>{if(s.preventDefault(),!le(c)){B(a.invalidEmail);return}Q.mutate({email:c})},De=s=>{if(s.preventDefault(),!le(c)){B(a.invalidEmail),x({type:"failed",method:"email_otp",stage:"validation",error:"invalid_email"});return}U.mutate({email:c})},Ne=s=>{P.isPending||P.mutate({email:c,otp:s})},qe=s=>{s.preventDefault(),ge.length===h.length&&Ne(ge)},Be=s=>{re(s),xe&&(U.reset(),P.reset())},Z=s=>o=>{s(o.target.value),Ie&&J.reset(),Ce&&Q.reset(),xe&&(U.reset(),P.reset()),s===ne&&C&&B("")},ee=s=>{$e(s),be(""),re(""),he(!1),B(""),we(!1),oe(null),J.reset(),Q.reset(),U.reset(),P.reset(),X.reset()},E=J.isPending||Q.isPending||U.isPending||P.isPending||X.isPending,Ie=J.error,Ce=Q.error,xe=U.error||P.error,K=I?c.trim()&&ie.trim()&&ue.trim():R||L?c.trim():c.trim()&&ie.trim(),ze=s=>{if(!s)return null;const o=s.message.toLowerCase();return o.includes("unauthorized")||o.includes("401")?a.invalidEmailOrPassword:o.includes("already exists")||o.includes("409")?a.accountExists:o.includes("network")||o.includes("fetch")?a.networkError:o.includes("rate limit")||o.includes("429")?a.tooManyAttempts:o.includes("invalid")&&o.includes("otp")?a.invalidOrExpiredCode:s.message||a.genericError},Pe=Ie||Ce||xe||Me||X.error,Ve=async s=>{x({type:"started",method:"social",provider:s}),oe(null),X.reset();try{const o=await w.socialSignIn({provider:s,callbackURL:n??e});if(o.error)throw new Error(o.error.message||a.authenticationFailed)}catch(o){const O=o instanceof Error?o.message:String(o);x({type:"failed",method:"social",provider:s,stage:"redirect",error:O}),M("social_signin_failed",{provider:s,error:O}),oe(o instanceof Error?o:new Error(O))}},He=R?a.resetPasswordTitle:L&&Y?a.verificationCodeTitle:r??a.welcomeTitle,Ae=R?a.resetPasswordSubtitle:L&&Y?a.codeSentTo(c):l===void 0?a.defaultSubtitle:l;return t.jsxs("div",{className:S("grid w-full",j?"gap-5":"gap-10"),children:[g??t.jsxs("div",{children:[t.jsx("img",{src:"/logos/deco logo.svg",alt:"Deco",className:"h-12 w-12 dark:hidden"}),t.jsx("img",{src:"/logos/deco logo negative.svg",alt:"Deco",className:"h-12 w-12 hidden dark:block"})]}),t.jsxs("div",{className:"space-y-2",children:[t.jsx("h1",{className:S("font-medium",j?"text-xl leading-7":"text-2xl leading-8"),children:He}),Ae&&t.jsx("p",{className:S("text-muted-foreground",j?"text-sm leading-5":"text-base leading-6"),children:Ae})]}),Pe&&t.jsx("div",{role:"alert",className:"rounded-xl bg-destructive/10 p-3 text-sm text-destructive text-center",children:ze(Pe)}),ve&&t.jsx("div",{role:"status",className:"rounded-xl bg-success/10 p-3 text-sm text-success text-center",children:a.resetEmailSent}),!R&&!(L&&Y)&&W&&t.jsxs("div",{className:"grid gap-2",children:[T&&_.map(s=>t.jsxs(se,{type:"button",variant:"outline",size:j?"lg":"xl",disabled:E,onClick:()=>{Ve(s.name)},className:"w-full gap-3",children:[s.icon&&t.jsx("img",{src:s.icon,alt:"",className:S("h-5 w-5",s.name==="github"&&"dark:invert"),"aria-hidden":"true"}),a.continueWith(s.name.charAt(0).toUpperCase()+s.name.slice(1))]},s.name)),F&&t.jsxs(se,{type:"button",variant:"outline",size:j?"lg":"xl",disabled:E,onClick:()=>{oe(null),X.mutate()},className:"w-full gap-3",children:[t.jsx(Je,{className:"h-5 w-5","aria-hidden":"true"}),a.signInWithPasskey]})]}),!R&&!(L&&Y)&&W&&(k||h.enabled)&&t.jsxs("div",{className:S("flex items-center gap-2.5",j?"my-0":"-my-4"),children:[t.jsx("div",{className:"h-px flex-1 bg-border"}),t.jsx("span",{className:S("text-muted-foreground",j?"text-sm":"text-base"),children:a.divider}),t.jsx("div",{className:"h-px flex-1 bg-border"})]}),L&&h.enabled&&t.jsx(t.Fragment,{children:Y?t.jsxs("form",{onSubmit:qe,className:"grid gap-2",children:[t.jsxs("div",{className:"grid gap-2",children:[t.jsx("label",{htmlFor:Se,className:S("text-sm font-medium text-foreground",j&&"sr-only"),children:a.verificationCodeLabel}),t.jsx(et,{id:Se,length:h.length,value:ge,onChange:Be,onComplete:Ne,autoFocus:!0,"aria-invalid":!!P.error,"aria-describedby":P.isPending?je:void 0}),t.jsx("p",{id:je,role:"status",className:S("text-sm text-muted-foreground",!P.isPending&&"sr-only"),children:P.isPending?a.verifying:""})]}),t.jsx("button",{type:"button",onClick:()=>{he(!1),re(""),U.reset(),P.reset()},disabled:E,className:"mt-1 text-sm text-muted-foreground transition-colors hover:text-foreground",children:a.useDifferentEmail})]}):t.jsxs("form",{onSubmit:De,className:S("grid gap-2",j&&"sm:grid-cols-[minmax(0,1fr)_auto] sm:items-start"),children:[t.jsxs("div",{className:"grid gap-2",children:[t.jsx("label",{htmlFor:V,className:S("text-sm font-medium text-foreground",j&&"sr-only"),children:a.emailLabel}),t.jsx(ae,{id:V,type:"email",placeholder:a.emailPlaceholder,value:c,onChange:Z(ne),onBlur:fe,required:!0,disabled:E,autoComplete:"email","aria-invalid":!!C,"aria-describedby":C?H:void 0,className:"h-11"}),C&&t.jsx("p",{id:H,role:"alert",className:"text-xs text-destructive",children:C})]}),t.jsx(se,{type:"submit",size:j?"lg":"xl",disabled:E||!K,className:S(j?"sm:w-auto":"w-full"),children:E?a.sending:a.sendCode})]})}),R&&k&&!ve&&t.jsxs("form",{onSubmit:Ue,className:"grid gap-4",children:[t.jsxs("div",{children:[t.jsx("label",{htmlFor:V,className:"block text-sm font-medium text-foreground mb-2",children:a.emailLabel}),t.jsx(ae,{id:V,type:"email",placeholder:"you@example.com",value:c,onChange:Z(ne),onBlur:fe,required:!0,disabled:E,autoComplete:"email","aria-invalid":!!C,"aria-describedby":C?H:void 0,className:"h-11"}),C&&t.jsx("p",{id:H,role:"alert",className:"text-xs text-destructive mt-1.5",children:C})]}),t.jsx(se,{type:"submit",disabled:E||!K,className:"w-full font-semibold",size:"xl",children:E?a.sending:a.sendResetLink})]}),!R&&!L&&k&&t.jsxs("form",{onSubmit:We,className:"grid gap-5",children:[I&&t.jsxs("div",{children:[t.jsx("label",{htmlFor:ye,className:"block text-sm font-medium text-foreground mb-2",children:a.nameLabel}),t.jsx(ae,{id:ye,type:"text",placeholder:a.namePlaceholder,value:ue,onChange:Z(be),required:!0,disabled:E,autoComplete:"name",className:"h-11"})]}),t.jsxs("div",{children:[t.jsx("label",{htmlFor:V,className:"block text-sm font-medium text-foreground mb-2",children:a.emailLabel}),t.jsx(ae,{id:V,type:"email",placeholder:"you@example.com",value:c,onChange:Z(ne),onBlur:fe,required:!0,disabled:E,autoComplete:"email","aria-invalid":!!C,"aria-describedby":C?H:void 0,className:"h-11"}),C&&t.jsx("p",{id:H,role:"alert",className:"text-xs text-destructive mt-1.5",children:C})]}),t.jsxs("div",{children:[t.jsxs("div",{className:"flex items-center justify-between mb-2",children:[t.jsx("label",{htmlFor:Ee,className:"block text-sm font-medium text-foreground",children:a.passwordLabel}),!I&&p.enabled&&t.jsx("button",{type:"button",onClick:()=>ee("forgotPassword"),className:"text-xs text-muted-foreground hover:text-foreground transition-colors",children:a.forgotPassword})]}),t.jsx(ae,{id:Ee,type:"password",placeholder:"••••••••",value:ie,onChange:Z(Re),required:!0,disabled:E,autoComplete:I?"new-password":"current-password",className:"h-11"})]}),t.jsx("div",{className:S("overflow-hidden transition-all duration-300 ease-[cubic-bezier(0.075,0.82,0.165,1)]",K?"max-h-[100px] opacity-100 translate-y-0":"max-h-0 opacity-0 -translate-y-2"),children:t.jsx("div",{className:S("p-1",!K&&"pointer-events-none"),children:t.jsx(se,{type:"submit",disabled:E||!K,className:S("w-full font-semibold"),size:"xl","aria-hidden":!K,children:E?I?a.creatingAccount:a.signingIn:a.continue})})})]}),t.jsx("div",{className:"text-sm text-muted-foreground",children:R?t.jsx("button",{type:"button",onClick:()=>ee("signIn"),disabled:E,className:de,children:a.backToSignIn}):L&&k?t.jsx("button",{type:"button",onClick:()=>ee("signIn"),disabled:E,className:de,children:a.signInWithPassword}):!L&&k?t.jsxs(t.Fragment,{children:[I?a.alreadyHaveAccount:a.dontHaveAccount,t.jsx("button",{type:"button",onClick:()=>ee(I?"signIn":"signUp"),disabled:E,className:de,children:I?a.signIn:a.signUp}),h.enabled&&t.jsxs(t.Fragment,{children:[t.jsx("span",{className:"mx-2",children:"·"}),t.jsx("button",{type:"button",onClick:()=>ee("emailOtp"),disabled:E,className:de,children:a.signInWithEmailCode})]})]}):null})]})}class _e{constructor(e){this.response=e}response}function nt(n){return n.startsWith("/")&&!n.startsWith("//")&&!n.startsWith("/\\")?n:"/"}function it({redirectTo:n,onAuthEvent:e}){const r=Fe(),[l,g]=N.useState(null),m=N.useEffectEvent(i=>{try{e?.(i)}catch{}});return N.useEffect(()=>{let i=!1;return(async()=>{m({type:"started",method:"local"});try{let u;try{u=await Ze(async()=>{const d=await fetch("/api/auth/custom/local-session",{method:"POST",credentials:"include"});if(d.status>=500)throw new _e(d);return d},{maxAttempts:5,minTimeout:1e3,maxTimeout:1e4,multiplier:2,jitter:0})}catch(d){if(d instanceof Le&&d.cause instanceof _e)u=d.cause.response;else throw d}if(!u.ok){const d=await u.json().catch(()=>({}));throw new Error(d?.error||r("common.authEntry.autoLoginFailed"))}i||(m({type:"succeeded",method:"local"}),window.location.href=nt(n))}catch(u){i||(m({type:"failed",method:"local",stage:"authenticate",error:u instanceof Error?u.message:String(u)}),g(u instanceof Error?u.message:r("common.authEntry.autoLoginFailed")))}})(),()=>{i=!0}},[n]),l?t.jsx("div",{className:"flex min-h-screen items-center justify-center",children:t.jsxs("div",{className:"text-center",children:[t.jsx("p",{className:"text-destructive mb-2",children:r("common.authEntry.autoLoginFailedWithError",{error:l})}),t.jsx("p",{className:"text-muted-foreground text-sm",children:r("common.authEntry.tryRestartingServer")})]})}):t.jsx(Te,{})}function Te(){const n=ce.c(1);let e;return n[0]===Symbol.for("react.memo_cache_sentinel")?(e=t.jsx("div",{className:"flex min-h-screen items-center justify-center",children:t.jsx(Ye,{size:"lg",label:"Signing in"})}),n[0]=e):e=n[0],e}function rt({callbackURL:n,providerId:e,ssoSignIn:r,onAuthEvent:l}){const g=N.useEffectEvent(i=>{try{l?.(i)}catch{}}),m=N.useEffectEvent(r);return N.useEffect(()=>{(async()=>{g({type:"started",method:"sso",provider:e});try{const i=await m({providerId:e,callbackURL:n});if(i.error)throw new Error(i.error.message||"SSO redirect failed")}catch(i){g({type:"failed",method:"sso",provider:e,stage:"redirect",error:i instanceof Error?i.message:String(i)})}})()},[e,n]),t.jsx(Te,{})}function mt(n){const e=ce.c(25),{callbackUrl:r,redirectUrl:l,allowAutoLogin:g,title:m,subtitle:i,brand:u,copy:d,variant:b,allowedSocialProviders:f,allowPassword:v,onAuthEvent:p,onAuthenticated:h}=n,A=g===void 0?!0:g,y=Fe(),{sso:w,emailAndPassword:x,magicLink:j,emailOtp:D,socialProviders:q,localMode:me}=ke(),_=l||r;let T;e[0]!==h?(T=h?{onAuthenticated:h}:void 0,e[0]=h,e[1]=T):T=e[1];const k=T;if(me&&A){let c;return e[2]!==p||e[3]!==_?(c=t.jsx(it,{redirectTo:_,onAuthEvent:p}),e[2]=p,e[3]=_,e[4]=c):c=e[4],c}if(w.enabled){let c;return e[5]!==p||e[6]!==_||e[7]!==w.providerId?(c=t.jsx(rt,{callbackURL:_,providerId:w.providerId,ssoSignIn:Oe.ssoSignIn,onAuthEvent:p}),e[5]=p,e[6]=_,e[7]=w.providerId,e[8]=c):c=e[8],c}if(x.enabled||j.enabled||D.enabled||q.enabled){let c;return e[9]!==v||e[10]!==f||e[11]!==u||e[12]!==r||e[13]!==k||e[14]!==d||e[15]!==p||e[16]!==l||e[17]!==i||e[18]!==m||e[19]!==b?(c=t.jsx(at,{redirectUrl:l,callbackUrl:r,title:m,subtitle:i,brand:u,copy:d,variant:b,allowedSocialProviders:f,allowPassword:v,onAuthEvent:p,actions:k}),e[9]=v,e[10]=f,e[11]=u,e[12]=r,e[13]=k,e[14]=d,e[15]=p,e[16]=l,e[17]=i,e[18]=m,e[19]=b,e[20]=c):c=e[20],c}let F;e[21]!==y?(F=y("common.authEntry.noLoginOptions"),e[21]=y,e[22]=F):F=e[22];let W;return e[23]!==F?(W=t.jsx("div",{children:F}),e[23]=F,e[24]=W):W=e[24],W}export{Te as A,mt as a};