"use strict";(self.webpackChunk_N_E=self.webpackChunk_N_E||[]).push([[7185],{54921:(e,t,s)=>{s.d(t,{CP:()=>er,Jv:()=>es,CI:()=>en,wV:()=>Y});var n=s(95155),r=s(12115);class a extends Error{constructor(e,t){e instanceof Error?super(void 0,{cause:{err:e,...e.cause,...t}}):"string"==typeof e?(t instanceof Error&&(t={err:t,...t.cause}),super(e,t)):super(void 0,e),this.name=this.constructor.name,this.type=this.constructor.type??"AuthError",this.kind=this.constructor.kind??"error",Error.captureStackTrace?.(this,this.constructor);const s=`https://errors.authjs.dev#${this.type.toLowerCase()}`;this.message+=`${this.message?". ":""}Read more at ${s}`}}class o extends a{}o.kind="signIn";class i extends a{}i.type="AdapterError";class c extends a{}c.type="AccessDenied";class l extends a{}l.type="CallbackRouteError";class u extends a{}u.type="ErrorPageLoop";class d extends a{}d.type="EventError";class h extends a{}h.type="InvalidCallbackUrl";class p extends o{constructor(){super(...arguments),this.code="credentials"}}p.type="CredentialsSignin";class f extends a{}f.type="InvalidEndpoints";class w extends a{}w.type="InvalidCheck";class v extends a{}v.type="JWTSessionError";class y extends a{}y.type="MissingAdapter";class g extends a{}g.type="MissingAdapterMethods";class E extends a{}E.type="MissingAuthorize";class m extends a{}m.type="MissingSecret";class x extends o{}x.type="OAuthAccountNotLinked";class S extends o{}S.type="OAuthCallbackError";class b extends a{}b.type="OAuthProfileParseError";class _ extends a{}_.type="SessionTokenError";class L extends o{}L.type="OAuthSignInError";class U extends o{}U.type="EmailSignInError";class R extends a{}R.type="SignOutError";class k extends a{}k.type="UnknownAction";class A extends a{}A.type="UnsupportedStrategy";class P extends a{}P.type="InvalidProvider";class C extends a{}C.type="UntrustedHost";class T extends a{}T.type="Verification";class $ extends o{}$.type="MissingCSRF";class N extends a{}N.type="DuplicateConditionalUI";class I extends a{}I.type="MissingWebAuthnAutocomplete";class M extends a{}M.type="WebAuthnVerificationError";class O extends o{}O.type="AccountNotLinked";class X extends a{}X.type="ExperimentalFeatureNotEnabled";class H extends a{}class j extends a{}async function W(e,t,s,n={}){let r=`${V(t)}/${e}`;try{let e={headers:{"Content-Type":"application/json",...n?.headers?.cookie?{cookie:n.headers.cookie}:{}}};n?.body&&(e.body=JSON.stringify(n.body),e.method="POST");let t=await fetch(r,e),s=await t.json();if(!t.ok)throw s;return s}catch(e){return s.error(new H(e.message,e)),null}}function V(e){return e.basePath}function D(){return Math.floor(Date.now()/1e3)}function F(e){let t=new URL("http://localhost:3000/api/auth");e&&!e.startsWith("http")&&(e=`https://${e}`);let s=new URL(e||t),n=("/"===s.pathname?t.pathname:s.pathname).replace(/\/$/,""),r=`${s.origin}${n}`;return{origin:s.origin,host:s.host,path:n,base:r,toString:()=>r}}var J=s(87358);let B={baseUrl:F(J.env.NEXTAUTH_URL??J.env.VERCEL_URL).origin,basePath:F(J.env.NEXTAUTH_URL).path,baseUrlServer:F(J.env.NEXTAUTH_URL_INTERNAL??J.env.NEXTAUTH_URL??J.env.VERCEL_URL).origin,basePathServer:F(J.env.NEXTAUTH_URL_INTERNAL??J.env.NEXTAUTH_URL).path,_lastSync:0,_session:void 0,_getSession:()=>{}},q=null;function z(){return"u"<typeof BroadcastChannel?{postMessage:()=>{},addEventListener:()=>{},removeEventListener:()=>{},name:"next-auth",onmessage:null,onmessageerror:null,close:()=>{},dispatchEvent:()=>!1}:new BroadcastChannel("next-auth")}function G(){return null===q&&(q=z()),q}let K={debug:console.debug,error:console.error,warn:console.warn},Q=r.createContext?.(void 0);function Y(e){if(!Q)throw Error("React Context is unavailable in Server Components");let t=r.useContext(Q),{required:s,onUnauthenticated:n}=e??{},a=s&&"unauthenticated"===t.status;return(r.useEffect(()=>{if(a){let e=`${B.basePath}/signin?${new URLSearchParams({error:"SessionRequired",callbackUrl:window.location.href})}`;n?n():window.location.href=e}},[a,n]),a)?{data:t.data,update:t.update,status:"loading"}:t}async function Z(e){let t=await W("session",B,K,e);return(e?.broadcast??!0)&&z().postMessage({event:"session",data:{trigger:"getSession"}}),t}async function ee(){let e=await W("csrf",B,K);return e?.csrfToken??""}async function et(){return W("providers",B,K)}async function es(e,t,s){let{callbackUrl:n,...r}=t??{},{redirect:a=!0,redirectTo:o=n??window.location.href,...i}=r,c=V(B),l=await et();if(!l){let e=`${c}/error`;window.location.href=e;return}if(!e||!l[e]){let e=`${c}/signin?${new URLSearchParams({callbackUrl:o})}`;window.location.href=e;return}let u=l[e].type;if("webauthn"===u)throw TypeError(`Provider id "${e}" refers to a WebAuthn provider.
Please use \`import { signIn } from "next-auth/webauthn"\` instead.`);let d=`${c}/${"credentials"===u?"callback":"signin"}/${e}`,h=await ee(),p=await fetch(`${d}?${new URLSearchParams(s)}`,{method:"post",headers:{"Content-Type":"application/x-www-form-urlencoded","X-Auth-Return-Redirect":"1"},body:new URLSearchParams({...i,csrfToken:h,callbackUrl:o})}),f=await p.json();if(a){let e=f.url??o;window.location.href=e,e.includes("#")&&window.location.reload();return}let w=new URL(f.url).searchParams.get("error")??void 0,v=new URL(f.url).searchParams.get("code")??void 0;return p.ok&&await B._getSession({event:"storage"}),{error:w,code:v,status:p.status,ok:p.ok,url:w?null:f.url}}async function en(e){let{redirect:t=!0,redirectTo:s=e?.callbackUrl??window.location.href}=e??{},n=V(B),r=await ee(),a=await fetch(`${n}/signout`,{method:"post",headers:{"Content-Type":"application/x-www-form-urlencoded","X-Auth-Return-Redirect":"1"},body:new URLSearchParams({csrfToken:r,callbackUrl:s})}),o=await a.json();if(G().postMessage({event:"session",data:{trigger:"signout"}}),t){let e=o.url??s;window.location.href=e,e.includes("#")&&window.location.reload();return}return await B._getSession({event:"storage"}),o}function er(e){if(!Q)throw Error("React Context is unavailable in Server Components");let{children:t,basePath:s,refetchInterval:a,refetchWhenOffline:o}=e;s&&(B.basePath=s);let i=void 0!==e.session;B._lastSync=i?D():0;let[c,l]=r.useState(()=>(i&&(B._session=e.session),e.session)),[u,d]=r.useState(!i);r.useEffect(()=>(B._getSession=async({event:e}={})=>{try{let t="storage"===e;if(t||void 0===B._session){B._lastSync=D(),B._session=await Z({broadcast:!t}),l(B._session);return}if(!e||null===B._session||D()<B._lastSync)return;B._lastSync=D(),B._session=await Z(),l(B._session)}catch(e){K.error(new j(e.message,e))}finally{d(!1)}},B._getSession(),()=>{B._lastSync=0,B._session=void 0,B._getSession=()=>{}}),[]),r.useEffect(()=>{let e=()=>B._getSession({event:"storage"});return G().addEventListener("message",e),()=>G().removeEventListener("message",e)},[]),r.useEffect(()=>{let{refetchOnWindowFocus:t=!0}=e,s=()=>{t&&"visible"===document.visibilityState&&B._getSession({event:"visibilitychange"})};return document.addEventListener("visibilitychange",s,!1),()=>document.removeEventListener("visibilitychange",s,!1)},[e.refetchOnWindowFocus]);let h=function(){let[e,t]=r.useState("u">typeof navigator&&navigator.onLine),s=()=>t(!0),n=()=>t(!1);return r.useEffect(()=>(window.addEventListener("online",s),window.addEventListener("offline",n),()=>{window.removeEventListener("online",s),window.removeEventListener("offline",n)}),[]),e}(),p=!1!==o||h;r.useEffect(()=>{if(a&&p){let e=setInterval(()=>{B._session&&B._getSession({event:"poll"})},1e3*a);return()=>clearInterval(e)}},[a,p]);let f=r.useMemo(()=>({data:c,status:u?"loading":c?"authenticated":"unauthenticated",async update(e){if(u)return;d(!0);let t=await W("session",B,K,void 0===e?void 0:{body:{csrfToken:await ee(),data:e}});return d(!1),t&&(l(t),G().postMessage({event:"session",data:{trigger:"getSession"}})),t}}),[c,u]);return(0,n.jsx)(Q.Provider,{value:f,children:t})}},73321:(e,t,s)=>{var n=s(74645);s.o(n,"usePathname")&&s.d(t,{usePathname:function(){return n.usePathname}}),s.o(n,"useRouter")&&s.d(t,{useRouter:function(){return n.useRouter}}),s.o(n,"useSearchParams")&&s.d(t,{useSearchParams:function(){return n.useSearchParams}})}}]);