import{o as e}from"./rolldown-runtime-BM3Ffeng.js";import{$f as t,B_ as n,Cv as r,Gn as i,Gy as a,Hy as o,Ln as s,Ly as c,Sv as l,Zl as u,ah as d,bp as f,bv as p,c_ as m,ch as h,dg as g,du as _,dv as v,fv as y,hl as b,jg as x,m_ as S,mv as C,ph as w,pv as T,sh as E,ty as D,vp as O}from"./index-DDwwBb9e.js";import{SignInError as k,normalizeErrorCode as A}from"./error-DNmmfsZh.js";var j=e(a()),M=o();function N(){let{data:e}=E(),t=i(),n=t?.get(`error`),r=A(n),a=h(),o=a.data?.NEXTAUTH_PROVIDER,s=t?.get(`callbackUrl`)??void 0,l=o&&o!==`email`;return(0,j.useEffect)(()=>{if(a.data){if(e){let e=s&&s.startsWith(`/`)?s:`/`;window.location.replace(e);return}r!==`OAuthAccountNotLinked`&&l&&setTimeout(()=>{d(o,{callbackUrl:s})},r?2e3:0)}},[a.data,e,s,o,l,r]),r?(0,M.jsx)(k,{error:r}):a.data?e?(0,M.jsx)(c,{padding:`12px`,children:`Already signed in — redirecting…`}):l?(0,M.jsx)(c,{padding:`12px`,children:`Redirecting to Sign in...`}):(0,M.jsx)(P,{}):null}function P(){let e=i(),a=e?.get(`error`),o=e?.get(`callbackUrl`)??void 0,h=t({resolver:_(O({email:f().email(),password:f()}))}),[E,k]=(0,j.useState)(!1);return(0,M.jsx)(n,{maxW:`container.md`,paddingTop:`calc(40vh - 164px)`,children:(0,M.jsx)(`form`,{onSubmit:h.handleSubmit(async e=>{try{k(!0);let t=await d(`credentials`,{email:e.email,password:e.password,callbackUrl:o});if(k(!1),t?.error)throw Error(`Sign in failed`);if(t?.status&&t.status>=400)throw Error(`Network response was not ok`)}catch{w.create({title:`Error`,description:`Failed to sign in`,type:`error`,meta:{closable:!0}})}}),children:(0,M.jsxs)(T,{children:[(0,M.jsx)(y,{children:(0,M.jsxs)(S,{gap:4,children:[(0,M.jsx)(s,{width:30.69,height:42}),(0,M.jsx)(D,{size:`lg`,as:`h1`,children:`Sign in`})]})}),(0,M.jsx)(v,{children:(0,M.jsxs)(g,{width:`full`,children:[(0,M.jsx)(u,{label:`Email`,helper:`Enter your email`,invalid:h.formState.errors.email?.message!==void 0,children:(0,M.jsx)(m,{type:`email`,...h.register(`email`)})}),(0,M.jsx)(u,{label:`Password`,helper:`Enter your password`,invalid:h.formState.errors.password?.message!==void 0,children:(0,M.jsx)(m,{type:`password`,...h.register(`password`)})}),a&&(0,M.jsxs)(r,{status:`error`,children:[(0,M.jsx)(l,{}),(0,M.jsx)(p,{children:a===`CredentialsSignin`?`Invalid email or password`:a})]}),(0,M.jsxs)(S,{width:`full`,paddingTop:4,children:[(0,M.jsx)(c,{asChild:!0,children:(0,M.jsx)(b,{href:`/auth/signup${o?`?callbackUrl=${encodeURIComponent(o)}`:``}`,style:{textDecoration:`underline`},children:`Register new account`})}),(0,M.jsx)(x,{}),(0,M.jsx)(C,{colorPalette:`orange`,type:`submit`,loading:E,children:`Sign in`})]})]})})]})})})}export{N as default};
//# sourceMappingURL=signin-CQ6cQRgD.js.map