(self.webpackChunk_N_E=self.webpackChunk_N_E||[]).push([[4520],{83016:(e,t,s)=>{"use strict";s.r(t),s.d(t,{default:()=>n});var a=s(95155),r=s(12115),i=s(35497),l=s(73321);function n(){let[e,t]=(0,r.useState)(""),[s,n]=(0,r.useState)(""),[o,d]=(0,r.useState)(!1),[c,u]=(0,r.useState)(null),[h,x]=(0,r.useState)("password"),[m,p]=(0,r.useState)(!1),[f,b]=(0,r.useState)("Sign in with OIDC"),g=(0,l.useRouter)();(0,r.useEffect)(()=>{!async function(){let e=new AbortController,t=setTimeout(()=>e.abort(),5e3),s=window.location.origin;try{let a=await fetch(`${s}/api/auth/status`,{signal:e.signal});if(clearTimeout(t),a.ok){let e=await a.json();if(!1===e.requireLogin){g.push("/dashboard"),g.refresh();return}u(!!e.hasPassword),x(e.authMode||"password"),p(!0===e.oidcConfigured),b(e.oidcLoginLabel||"Sign in with OIDC")}else u(!0)}catch(e){clearTimeout(t),u(!0)}}()},[g]);let w=async t=>{t.preventDefault(),d(!0),n("");try{let t=await fetch("/api/auth/login",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({password:e})});if(t.ok)g.push("/dashboard"),g.refresh();else{let e=await t.json();n(e.error||"Invalid password")}}catch(e){n("An error occurred. Please try again.")}finally{d(!1)}},j=m&&["oidc","both"].includes(h),N="oidc"!==h||!m;return null===c?(0,a.jsx)("div",{className:"min-h-screen flex items-center justify-center bg-bg p-4",children:(0,a.jsxs)("div",{className:"text-center",children:[(0,a.jsx)("div",{className:"inline-block animate-spin rounded-full h-8 w-8 border-b-2 border-primary"}),(0,a.jsx)("p",{className:"text-text-muted mt-4",children:"Loading..."})]})}):(0,a.jsxs)("div",{className:"min-h-screen flex items-center justify-center bg-bg p-4 relative overflow-hidden",children:[(0,a.jsx)("div",{className:"landing-grid absolute inset-0 pointer-events-none","aria-hidden":"true"}),(0,a.jsxs)("div",{className:"relative z-10 w-full max-w-md",children:[(0,a.jsxs)("div",{className:"text-center mb-8",children:[(0,a.jsx)("h1",{className:"text-3xl font-bold text-primary mb-2",children:"KTRouter"}),(0,a.jsx)("p",{className:"text-text-muted",children:"oidc"===h&&m?"Sign in with your OIDC provider to access the dashboard":"Enter your password to access the dashboard"})]}),(0,a.jsx)(i.Zp,{children:(0,a.jsxs)("div",{className:"flex flex-col gap-4",children:[j&&(0,a.jsx)(i.$n,{type:"button",variant:"primary",className:"w-full",onClick:()=>{window.location.href="/api/auth/oidc/start"},children:f}),j&&N&&(0,a.jsx)("div",{className:"h-px bg-border/60"}),N?(0,a.jsxs)("form",{onSubmit:w,className:"flex flex-col gap-4",children:[("oidc"===h&&!m||"both"===h&&!m)&&(0,a.jsx)("p",{className:"text-xs text-amber-600 dark:text-amber-400 text-center",children:"OIDC login is enabled, but the issuer/client fields are not configured yet. Password login is still available for recovery."}),"both"===h&&m&&(0,a.jsx)("p",{className:"text-xs text-text-muted text-center",children:"Password and OIDC login are both enabled."}),(0,a.jsxs)("div",{className:"flex flex-col gap-2",children:[(0,a.jsx)("label",{className:"text-sm font-medium",children:"Password"}),(0,a.jsx)(i.pd,{type:"password",placeholder:"Enter password",value:e,onChange:e=>t(e.target.value),required:!0,autoFocus:!j}),s&&(0,a.jsx)("p",{className:"text-xs text-red-500",children:s})]}),(0,a.jsx)(i.$n,{type:"submit",variant:"primary",className:"w-full",loading:o,children:"Login"}),!1===c&&(0,a.jsx)("p",{className:"text-xs text-center text-text-muted",children:"No custom password is set yet. Use the configured initial password from your environment until you change it."})]}):s&&(0,a.jsx)("p",{className:"text-xs text-red-500",children:s})]})})]})]})}},90854:(e,t,s)=>{Promise.resolve().then(s.bind(s,83016))}},e=>{e.O(0,[2574,3862,2194,698,1321,5497,8441,3794,7358],()=>e(e.s=90854)),_N_E=e.O()}]);