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