1"use strict";(self.webpackChunk_N_E=self.webpackChunk_N_E||[]).push([[16565],{409098:(e,t,n)=>{Object.defineProperty(t,"__esModule",{value:!0});var r={callServer:function(){return l.callServer},createServerReference:function(){return i.createServerReference},findSourceMapURL:function(){return o.findSourceMapURL}};for(var a in r)Object.defineProperty(t,a,{enumerable:!0,get:r[a]});let l=n(607453),o=n(339381),i=n(470706)},525350:(e,t,n)=>{n.d(t,{ConvexAuthNextjsClientProvider:()=>i});var r=n(699892),a=n(494936),l=n(979188),o=n(507442);function i(e){let{apiRoute:t,serverState:n,storage:i,storageNamespace:u,shouldHandleCode:s,verbose:c,children:d}=e,h=(0,a.useCallback)(async(e,n)=>{let r=await fetch(null!=t?t:"/api/auth",{body:JSON.stringify({action:e,args:n}),method:"POST"});if(r.status>=400)throw Error((await r.json()).error);return await r.json()},[t]),f=(0,a.useMemo)(()=>({authenticatedCall:h,unauthenticatedCall:h,verbose:c}),[h,c]);return(0,r.jsx)(l.OJ,{client:f,serverState:n,onChange:o.g,storage:"u"<typeof window?void 0:"inMemory"===i?null:window.localStorage,storageNamespace:null!=u?u:function(e,t){if(void 0===e)throw Error("Missing environment variable `".concat(t,"`"));return e}("https://convex-ulta.filefactory.com","NEXT_PUBLIC_CONVEX_URL"),replaceURL:e=>{window.history.replaceState({},"",e)},shouldHandleCode:s,children:d})}},979188:(e,t,n)=>{n.d(t,{OJ:()=>g,eB:()=>u,sB:()=>d,As:()=>c});var r=n(699892),a=n(494936);let l=Object.prototype.toString,o=new Set(["network error","Failed to fetch","NetworkError when attempting to fetch resource.","The Internet connection appears to be offline.","Network request failed","fetch failed","terminated"," A network error occurred.","Network connection lost"]),i=[500,2e3],u=(0,a.createContext)(void 0),s=(0,a.createContext)(void 0);function c(){return(0,a.useContext)(s)}let d=(0,a.createContext)(null),h="__convexAuthOAuthVerifier",f="__convexAuthJWT",w="__convexAuthRefreshToken",v="__convexAuthServerStateFetchTime";function g({client:e,serverState:t,onChange:n,shouldHandleCode:c,storage:y,storageNamespace:m,replaceURL:_,children:b}){var p,x;let A,R,M,E,I=(0,a.useRef)(t?._state.token??null),[P,T]=(0,a.useState)(null===I.current),[$,j]=(0,a.useState)(I.current),L=e.verbose??!1,N=(0,a.useCallback)(t=>{L&&(console.debug(`${new Date().toISOString()} ${t}`),e.logger?.logVerbose(t))},[L]),{storageSet:O,storageGet:U,storageRemove:F,storageKey:V}=(p=y,x=m,A=function(){let[e,t]=(0,a.useState)({});return()=>({getItem:t=>e[t],setItem:(e,n)=>{t(t=>({...t,[e]:n}))},removeItem:e=>{t(t=>{let{[e]:n,...r}=t;return r})}})}(),R=(0,a.useMemo)(()=>p??A(),[p]),M=x.replace(/[^a-zA-Z0-9]/g,""),E=(0,a.useCallback)(e=>`${e}_${M}`,[x]),{storageSet:(0,a.useCallback)((e,t)=>R.setItem(E(e),t),[R,E]),storageGet:(0,a.useCallback)(e=>R.getItem(E(e)),[R,E]),storageRemove:(0,a.useCallback)(e=>R.removeItem(E(e)),[R,E]),storageKey:E}),[J,q]=(0,a.useState)(!1),B=(0,a.useCallback)(async e=>{let t,r=null!==I.current;if(null===e.tokens)I.current=null,e.shouldStore&&(await F(f),await F(w)),t=null;else{let{token:n}=e.tokens;if(I.current=n,e.shouldStore){let{refreshToken:t}=e.tokens;await O(f,n),await O(w,t)}t=n}r!==(null!==t)&&await n?.(),j(t),T(!1)},[O,F]);(0,a.useEffect)(()=>{let e=async e=>{if(J)return e.preventDefault(),e.returnValue=!0,"Are you sure you want to leave? Your changes may not be saved."};return S("beforeunload",e),()=>{C("beforeunload",e)}}),(0,a.useEffect)(()=>{let e=e=>{(async()=>{if(e.storageArea===y&&e.key===V(f)){let t=e.newValue;N(`synced access token, is null: ${null===t}`),await B({shouldStore:!1,tokens:null===t?null:{token:t}})}})()};return S("storage",e),()=>C("storage",e)},[B]);let D=(0,a.useCallback)(async t=>{let n,r=0;for(;r<i.length;)try{return await e.unauthenticatedCall("auth:signIn","code"in t?{params:{code:t.code},verifier:t.verifier}:t)}catch(t){if(n=t,!function(e){if(!(e&&"[object Error]"===l.call(e)&&"TypeError"===e.name&&"string"==typeof e.message))return!1;let{message:t,stack:n}=e;return"Load failed"===t?void 0===n||"__sentry_captured__"in e:!!t.startsWith("error sending request for url")||o.has(t)}(t))break;let e=i[r]+100*Math.random();r++,N(`verifyCode failed with network error, retry ${r} of ${i.length} in ${e}ms`),await new Promise(t=>setTimeout(t,e))}throw n},[e]),W=(0,a.useCallback)(async e=>{let{tokens:t}=await D(e);return N(`retrieved tokens, is null: ${null===t}`),await B({shouldStore:!0,tokens:t??null}),null!==t},[e,B]),X=(0,a.useCallback)(async(t,n)=>{let r=n instanceof FormData?Array.from(n.entries()).reduce((e,[t,n])=>(e[t]=n,e),{}):n??{},a=await U(h)??void 0;await F(h);let l=await e.authenticatedCall("auth:signIn",{provider:t,params:r,verifier:a});if(void 0!==l.redirect){let e=new URL(l.redirect);return await O(h,l.verifier),"ReactNative"!==navigator.product&&(window.location.href=e.toString()),{signingIn:!1,redirect:e}}if(void 0!==l.tokens){let{tokens:e}=l;return N(`signed in and got tokens, is null: ${null===e}`),await B({shouldStore:!0,tokens:e}),{signingIn:null!==l.tokens}
1}return{signingIn:!1}},[e,B,U]),z=(0,a.useCallback)(async()=>{try{await e.authenticatedCall("auth:signOut")}catch(e){}N("signed out, erasing tokens"),await B({shouldStore:!0,tokens:null})},[B,e]),G=(0,a.useCallback)(async({forceRefreshToken:e})=>{if(e){let e=I.current;return await k(w,async()=>{let t=I.current;if(t!==e)return N(`returning synced token, is null: ${null===t}`),t;let n=await U(w)??null;return null!==n?(q(!0),await W({refreshToken:n}).finally(()=>{q(!1)}),N(`returning retrieved token, is null: ${null===t}`),I.current):(q(!1),N("returning null, there is no refresh token"),null)})}return I.current},[W,z,U]),H=(0,a.useRef)(!1);(0,a.useEffect)(()=>{if(void 0===y)throw Error("`localStorage` is not available in this environment, set the `storage` prop on `ConvexAuthProvider`!");let e=async()=>{let e=await U(f)??null;N(`retrieved token from storage, is null: ${null===e}`),await B({shouldStore:!1,tokens:null===e?null:{token:e}})};if(void 0!==t){let n=U(v),r=n=>{if(!n||t._timeFetched>+n){let{token:e,refreshToken:n}=t._state;O(v,t._timeFetched.toString()),B({tokens:null===e||null===n?null:{token:e,refreshToken:n},shouldStore:!0})}else e()};n instanceof Promise?n.then(r):r(n);return}let n=void 0!==window?.location?.search?new URLSearchParams(window.location.search).get("code"):null;if((H.current||n)&&!H.current&&(void 0===c||("function"==typeof c?c():c))){H.current=!0;let e=new URL(window.location.href);e.searchParams.delete("code"),(async()=>{await _(e.pathname+e.search+e.hash),await X(void 0,{code:n}),H.current=!1})()}else e()},[e,U]);let Y=(0,a.useMemo)(()=>({signIn:X,signOut:z}),[X,z]),Z=null!==$,K=(0,a.useMemo)(()=>({isLoading:P,isAuthenticated:Z,fetchAccessToken:G}),[G,P,Z]);return(0,r.jsx)(s.Provider,{value:K,children:(0,r.jsx)(u.Provider,{value:Y,children:(0,r.jsx)(d.Provider,{value:$,children:b})})})}async function k(e,t){let n=window?.navigator?.locks;return void 0!==n?await n.request(e,t):await b(e,t)}function y(e){void 0===globalThis.__convexAuthMutexes&&(globalThis.__convexAuthMutexes={});let t=globalThis.__convexAuthMutexes[e];return void 0===t&&(globalThis.__convexAuthMutexes[e]={currentlyRunning:null,waiting:[]}),t=globalThis.__convexAuthMutexes[e]}function m(e,t){globalThis.__convexAuthMutexes[e]=t}async function _(e,t){let n=y(e);null===n.currentlyRunning?m(e,{currentlyRunning:t().finally(()=>{let t=y(e).waiting.shift();y(e).currentlyRunning=null,m(e,{...y(e),currentlyRunning:void 0===t?null:_(e,t)})}),waiting:[]}):m(e,{...n,waiting:[...n.waiting,t]})}async function b(e,t){return new Promise((n,r)=>{_(e,()=>t().then(e=>n(e)).catch(e=>r(e)))})}function S(e,t,n){window.addEventListener?.(e,t,n)}function C(e,t,n){window.removeEventListener?.(e,t,n)}}}]);
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.