"use strict";(self.webpackChunk_N_E=self.webpackChunk_N_E||[]).push([[32870],{32870:function(e,t,n){n.d(t,{SessionProvider:function(){return ed},signIn:function(){return el},signOut:function(){return ec},kP:function(){return er}});var s,r,a,o,i,l=n(57437),c=n(2265),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 v extends u{}v.kind="signIn";class h extends u{}h.type="AdapterError";class p extends u{}p.type="AccessDenied";class f extends u{}f.type="CallbackRouteError";class w extends u{}w.type="ErrorPageLoop";class y extends u{}y.type="EventError";class g extends u{}g.type="InvalidCallbackUrl";class E extends v{constructor(){super(...arguments),this.code="credentials"}}E.type="CredentialsSignin";class S extends u{}S.type="InvalidEndpoints";class x extends u{}x.type="InvalidCheck";class b extends u{}b.type="JWTSessionError";class m extends u{}m.type="MissingAdapter";class _ extends u{}_.type="MissingAdapterMethods";class U extends u{}U.type="MissingAuthorize";class L extends u{}L.type="MissingSecret";class k extends v{}k.type="OAuthAccountNotLinked";class R extends v{}R.type="OAuthCallbackError";class A extends u{}A.type="OAuthProfileParseError";class T extends u{}T.type="SessionTokenError";class C extends v{}C.type="OAuthSignInError";class P extends v{}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 H extends u{}H.type="Verification";class j extends v{}j.type="MissingCSRF";class W extends u{}W.type="DuplicateConditionalUI";class V extends u{}V.type="MissingWebAuthnAutocomplete";class $ extends u{}$.type="WebAuthnVerificationError";class D extends v{}D.type="AccountNotLinked";class F extends u{}F.type="ExperimentalFeatureNotEnabled";class B extends u{}class J extends u{}async function q(e,t,n){let s=arguments.length>3&&void 0!==arguments[3]?arguments[3]:{},r="".concat(z(t),"/").concat(e);try{var a;let e={headers:{"Content-Type":"application/json",...(null==s?void 0:null===(a=s.headers)||void 0===a?void 0:a.cookie)?{cookie:s.headers.cookie}:{}}};(null==s?void 0:s.body)&&(e.body=JSON.stringify(s.body),e.method="POST");let t=await fetch(r,e),n=await t.json();if(!t.ok)throw n;return n}catch(e){return n.error(new B(e.message,e)),null}}function z(e){return"undefined"==typeof window?"".concat(e.baseUrlServer).concat(e.basePathServer):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(/\/$/,""),r="".concat(n.origin).concat(s);return{origin:n.origin,host:n.host,path:s,base:r,toString:()=>r}}var Q=n(25566);let Y={baseUrl:K(null!==(r=Q.env.NEXTAUTH_URL)&&void 0!==r?r:Q.env.VERCEL_URL).origin,basePath:K(Q.env.NEXTAUTH_URL).path,baseUrlServer:K(null!==(o=null!==(a=Q.env.NEXTAUTH_URL_INTERNAL)&&void 0!==a?a:Q.env.NEXTAUTH_URL)&&void 0!==o?o:Q.env.VERCEL_URL).origin,basePathServer:K(null!==(i=Q.env.NEXTAUTH_URL_INTERNAL)&&void 0!==i?i:Q.env.NEXTAUTH_URL).path,_lastSync:0,_session:void 0,_getSession:()=>{}},Z=null;function ee(){return new BroadcastChannel("next-auth")}function et(){return"undefined"==typeof BroadcastChannel?{postMessage:()=>{},addEventListener:()=>{},removeEventListener:()=>{}}:(null===Z&&(Z=ee()),Z)}let en={debug:console.debug,error:console.error,warn:console.warn},es=null===(s=c.createContext)||void 0===s?void 0:s.call(d,void 0);function er(e){if(!es)throw Error("React Context is unavailable in Server Components");let t=c.useContext(es),{required:n,onUnauthenticated:s}=null!=e?e:{},r=n&&"unauthenticated"===t.status;return(c.useEffect(()=>{if(r){let e="".concat(Y.basePath,"/signin?").concat(new URLSearchParams({error:"SessionRequired",callbackUrl:window.location.href}));s?s():window.location.href=e}},[r,s]),r)?{data:t.data,update:t.update,status:"loading"}:t}async function ea(e){var t;let n=await q("session",Y,en,e);return(null===(t=null==e?void 0:e.broadcast)||void 0===t||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)&&void 0!==e?e:""}async function ei(){return q("providers",Y,en)}async function el(e,t,n){var s,r,a;let{redirect:o=!0}=null!=t?t:{},i=null!==(r=null!==(s=null==t?void 0:t.redirectTo)&&void 0!==s?s:null==t?void 0:t.callbackUrl)&&void 0!==r?r:window.location.href,l=z(Y),c=await ei();if(!c){window.location.href="".concat(l,"/error");return}if(!e||!(e in c)){window.location.href="".concat(l,"/signin?").concat(new URLSearchParams({callbackUrl:i}));return}let d="credentials"===c[e].type,u="email"===c[e].type,v="".concat(l,"/").concat(d?"callback":"signin","/").concat(e),h=await eo(),p=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({...t,csrfToken:h,callbackUrl:i})}),f=await p.json();if(o||!(d||u)){let e=null!==(a=f.url)&&void 0!==a?a:i;window.location.href=e,e.includes("#")&&window.location.reload();return}let w=new URL(f.url).searchParams.get("error"),y=new URL(f.url).searchParams.get("code");return p.ok&&await Y._getSession({event:"storage"}),{error:w,code:y,status:p.status,ok:p.ok,url:w?null:f.url}}async function ec(e){var t,n,s,r;let a=null!==(n=null!==(t=null==e?void 0:e.redirectTo)&&void 0!==t?t:null==e?void 0:e.callbackUrl)&&void 0!==n?n:window.location.href,o=z(Y),i=await eo(),l=await fetch("".concat(o,"/signout"),{method:"post",headers:{"Content-Type":"application/x-www-form-urlencoded","X-Auth-Return-Redirect":"1"},body:new URLSearchParams({csrfToken:i,callbackUrl:a})}),c=await l.json();if(et().postMessage({event:"session",data:{trigger:"signout"}}),null===(s=null==e?void 0:e.redirect)||void 0===s||s){let e=null!==(r=c.url)&&void 0!==r?r:a;window.location.href=e,e.includes("#")&&window.location.reload();return}return await Y._getSession({event:"storage"}),c}function ed(e){if(!es)throw Error("React Context is unavailable in Server Components");let{children:t,basePath:n,refetchInterval:s,refetchWhenOffline:r}=e;n&&(Y.basePath=n);let a=void 0!==e.session;Y._lastSync=a?G():0;let[o,i]=c.useState(()=>(a&&(Y._session=e.session),e.session)),[d,u]=c.useState(!a);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 ea({broadcast:!t}),i(Y._session);return}if(!e||null===Y._session||G()<Y._lastSync)return;Y._lastSync=G(),Y._session=await ea(),i(Y._session)}catch(e){en.error(new J(e.message,e))}finally{u(!1)}},Y._getSession(),()=>{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 v=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}(),h=!1!==r||v;c.useEffect(()=>{if(s&&h){let e=setInterval(()=>{Y._session&&Y._getSession({event:"poll"})},1e3*s);return()=>clearInterval(e)}},[s,h]);let p=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:p,children:t})}}}]);