1import{j as e}from"./vendor-ui-Cmvb7Owm.js";import{h as S,r as l}from"./vendor-react-DT3EBgZv.js";import{a7 as b,a8 as h,K as N,s as o,e as k,N as E,v as C,w as P,x as D,Q as q,y as I,R as x,I as f,a5 as L,a6 as F,B as _,F as A}from"./index-5g62s0Db.js";import"./vendor-data-EeBZkdt7.js";import"./vendor-charts-Ly3mFSe7.js";import"./vendor-editor-D2klMk7-.js";import"./vendor-dnd-B5czVS4k.js";const T=b({email:h().email("Please enter a valid email address"),password:h().min(1,"Password is required")}),M=()=>{const i=S(),{toast:c}=N(),[m,d]=l.useState(!1),[n,g]=l.useState(!1),[r,u]=l.useState({email:"",password:""});l.useEffect(()=>{w();const{data:{subscription:s}}=o.auth.onAuthStateChange((a,t)=>{t&&a==="SIGNED_IN"&&i("/speaker-portal")});return()=>s.unsubscribe()},[i]);const w=async()=>{const{data:{session:s}}=await o.auth.getSession();if(s){const{data:a,error:t}=await o.from("user_roles").select("role").eq("user_id",s.user.id).eq("role","speaker").maybeSingle();t&&console.error("Error fetching speaker role:",t),a&&i("/speaker-portal")}},j=async s=>{s.preventDefault(),d(!0);try{const a=T.safeParse({email:r.email,password:r.password});if(!a.success){c({title:"Validation Error",description:a.error.errors[0].message,variant:"destructive"}),d(!1);return}const{data:t,error:p}=await o.auth.signInWithPassword({email:r.email,password:r.password});if(p)throw p;const{data:y,error:v}=await o.from("user_roles").select("role").eq("user_id",t.user.id).eq("role","speaker").maybeSingle();if(v||!y)throw await o.auth.signOut(),new Error("You don't have speaker access. Please contact the administrator.");c({title:"Success",description:"Logged in successfully"}),i("/speaker-portal")}catch(a){const t=a instanceof Error?a.message:"An error occurred during login";c({title:"Error",description:t,variant:"destructive"})}finally{d(!1)}};return e.jsxs(e.Fragment,{children:[e.jsx(k,{titlePrefix:"Speaker Login",description:"Sign in to your speaker portal",noIndex:!0}),e.jsxs("div",{className:"min-h-screen flex flex-col pt-page",children:[e.jsx(E,{}),e.jsx("main",{className:"flex-1 container mx-auto px-4 py-12 flex items-center justify-center min-h-[80vh]",children:e.jsxs(C,{className:"w-full max-w-md",children:[e.jsxs(P,{children:[e.jsx(D,{children:"Speaker Portal Login"}),e.jsx(q,{children:"Sign in to manage your submissions and sessions"})]}),e.jsx(I,{children:e.jsxs("form",{onSubmit:j,className:"space-y-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(x,{htmlFor:"email",children:"Email Address"}),e.jsx(f,{id:"email",type:"email",placeholder:"[email protected]",value:r.email,onChange:s=>u({...r,email:s.target.value}),required:!0})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(x,{htmlFor:"password",children:"Password"}),e.jsxs("div",{className:"relative",children:[e.jsx(f,{id:"password",type:n?"text":"password",value:r.password,onChange:s=>u({...r,password:s.target.value}),required:!0,className:"pr-10"}),e.jsx("button",{type:"button",onClick:()=>g(!n),className:"absolute right-3 top-1/2 -translate-y-1/2 text-muted-foreground hover:text-foreground transition-colors","aria-label":n?"Hide password":"Show password",children:n?e.jsx(L,{size:18}):e.jsx(F,{size:18})})]})]}),e.jsx(_,{type:"submit",className:"w-full",disabled:m,children:m?"Please wait...":"Sign In"}),e.jsx("p",{className:"text-center text-sm text-muted-foreground",children:"Don't have an account? Contact the administrator."})]})})]})}),e.jsx(A,{})]})]})};export{M 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.