1import{r as n,W as L,j as a,a9 as k,q as x,I as g,B as C,U as t,az as d}from"./index-CRQcHE7J.js";import{C as E,a as S,b as _,d as F,c as I}from"./card-DWLMxT6t.js";import{l as q}from"./auth-validation-BKaxuYkg.js";import"./types-By9teAtI.js";const V=()=>{const[l,v]=n.useState(""),[m,w]=n.useState(""),[u,h]=n.useState(!1),[c,f]=n.useState({}),o=L();n.useEffect(()=>{(async()=>{const{data:{session:e}}=await t.auth.getSession();if(e){const{data:s}=await t.rpc("has_role",{_user_id:e.user.id,_role:"admin"});s&&o("/morvo-internal-9f4k2x/dashboard")}})()},[o]);const j=async i=>{i.preventDefault(),f({});const e=q.safeParse({email:l,password:m});if(!e.success){const s={};e.error.errors.forEach(r=>{r.path[0]==="email"&&(s.email=r.message),r.path[0]==="password"&&(s.password=r.message)}),f(s);return}h(!0);try{const{data:s,error:r}=await t.auth.signInWithPassword({email:e.data.email,password:e.data.password});if(r)throw r;const{data:y,error:p}=await t.rpc("has_role",{_user_id:s.user.id,_role:"admin"});if(p)throw p;if(!y){await t.auth.signOut(),d.error("Access denied. Admin privileges required.");return}const{data:b}=await t.auth.mfa.getAuthenticatorAssuranceLevel(),{data:N}=await t.auth.mfa.listFactors();if(!N?.totp?.some(A=>A.status==="verified")){o("/morvo-internal-9f4k2x/mfa-setup");return}if(b?.currentLevel!=="aal2"){o("/morvo-internal-9f4k2x/mfa-verify");return}d.success("Welcome to Morvo Admin"),o("/morvo-internal-9f4k2x/dashboard")}catch(s){d.error(s.message||"Failed to login")}finally{h(!1)}};return a.jsx("div",{className:"min-h-screen flex items-center justify-center bg-gradient-to-br from-background via-background to-primary/5",children:a.jsxs(E,{className:"w-full max-w-md",children:[a.jsxs(S,{className:"space-y-4 text-center",children:[a.jsx("div",{className:"flex justify-center",children:a.jsx("img",{src:k,alt:"Morvo Logo",className:"h-12"})}),a.jsx(_,{className:"text-2xl",children:"Admin Dashboard"}),a.jsx(F,{children:"Internal access only"})]}),a.jsx(I,{children:a.jsxs("form",{onSubmit:j,className:"space-y-4",children:[a.jsxs("div",{className:"space-y-2",children:[a.jsx(x,{htmlFor:"email",children:"Email"}),a.jsx(g,{id:"email",type:"email",placeholder:"[email protected]",value:l,onChange:i=>v(i.target.value),maxLength:255,required:!0}),c.email&&a.jsx("p",{className:"text-sm text-destructive",children:c.email})]}),a.jsxs("div",{className:"space-y-2",children:[a.jsx(x,{htmlFor:"password",children:"Password"}),a.jsx(g,{id:"password",type:"password",value:m,onChange:i=>w(i.target.value),maxLength:128,required:!0}),c.password&&a.jsx("p",{className:"text-sm text-destructive",children:c.password})]}),a.jsx(C,{type:"submit",className:"w-full",disabled:u,children:u?"Signing In...":"Sign In"})]})})]})})};export{V as default};
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.