{"version":3,"file":"Auth.DUnVd02P.mjs","names":["useStore","useState"],"sources":["https:/framerusercontent.com/modules/vj7bFUjvEQFgEzNBkdoG/vf3CKm378wlVcBk7IhSU/createStore.js","https:/framer.com/m/framer/store.js@^1.0.0","https:/framerusercontent.com/modules/fZpVFlLItW095zMwbwVl/1V6vOGPTD5rSgRW8nFF7/Auth.js"],"sourcesContent":["import{useState,useEffect}from\"react\";import{Data,useObserveData}from\"framer\";export function createStore(state1){// Use Data so that a Preview reload resets the state\nconst dataStore=Data({state:Object.freeze({...state1})});// Create a set function that updates the state\nconst setDataStore=newState=>{// If the state is an object, make sure we copy it\nif(typeof newState===\"function\"){newState=newState(dataStore.state);}dataStore.state=Object.freeze({...dataStore.state,...newState});};// Store the initial state, copy the object if it's an object\nlet storeState=typeof state1===\"object\"?Object.freeze({...state1}):state1;// Keep a list of all the listeners, in the form of React hook setters\nconst storeSetters=new Set();// Create a set function that updates all the listeners / setters\nconst setStoreState=newState=>{// If the state is an object, make sure we copy it\nif(typeof newState===\"function\"){newState=newState(storeState);}storeState=typeof newState===\"object\"?Object.freeze({...storeState,...newState}):newState;// Update all the listeners / setters with the new value\nstoreSetters.forEach(setter=>setter(storeState));};// Create the actual hook based on everything above\nfunction useStore(){// Create the hook we are going to use as a listener\nconst[state,setState]=useState(storeState);// If we unmount the component using this hook, we need to remove the listener\n// @ts-ignore\nuseEffect(()=>{// But right now, we need to add the listener\nstoreSetters.add(setState);return()=>storeSetters.delete(setState);},[]);// If Data context exists, use Data, otherwise use vanilla React state\nif(useObserveData()===true){useObserveData();return[dataStore.state,setDataStore];}else{// Return the state and a function to update the central store\nreturn[state,setStoreState];}}return useStore;}\nexport const __FramerMetadata__ = {\"exports\":{\"createStore\":{\"type\":\"function\",\"annotations\":{\"framerContractVersion\":\"1\"}},\"__FramerMetadata__\":{\"type\":\"variable\"}}}\n//# sourceMappingURL=./createStore.map","/*\n * createStore (framer/store@1.0.1)\n *\n * Learn More: https://www.framer.com/asset-urls\n */\n\nexport * from \"https://framerusercontent.com/modules/vj7bFUjvEQFgEzNBkdoG/vf3CKm378wlVcBk7IhSU/createStore.js\"\n","import{jsx as _jsx}from\"react/jsx-runtime\";import{createStore}from\"https://framer.com/m/framer/store.js@^1.0.0\";import{useEffect}from\"react\";// Create the store with a default value\nconst useStore=createStore({authenticated:false,loaded:false,session:null,user:null});const isValidToken=expires_at=>{const currentTime=Date.now();return expires_at>currentTime&&expires_at.toString().length==currentTime.toString().length;};export function withCheckAuth(Component){return props=>{const[store,setStore]=useStore();useEffect(()=>{// Retrieve the access_token from localStorage\nconst session=localStorage.getItem(\"nx-session\");if(session){const{access_token,expires_at}=JSON.parse(session);// If expiration date of token exists\nif(expires_at){if(isValidToken(expires_at)){setStore({authenticated:true,loaded:true});}else{setStore({authenticated:false,loaded:true});console.error(\"Token has expired\");}}else{setStore({authenticated:false,loaded:true});console.error(\"No expiry found in session\");}/*\n                // If we have a valid access_token, make the fetch call\n                if (access_token) {\n                    fetch(\n                        \"https://x8ki-letl-twmt.n7.xano.io/api:elH4PkAS/auth/me\",\n                        {\n                            method: \"GET\",\n                            headers: {\n                                \"Content-Type\": \"application/json\",\n                                Authorization: `Bearer ${access_token}`, // Add token to Authorization header\n                            },\n                        }\n                    )\n                        .then((response) => response.json())\n                        .then((data) => {\n                            localStorage.setItem(\n                                \"nx-user\",\n                                JSON.stringify(data)\n                            )\n                            setStore({ authenticated: true, loaded: true })\n                        })\n                        .catch((error) => {\n                            console.error(\"Error fetching data:\", error)\n                            setStore({ authenticated: false, loaded: true })\n                        })\n                } else {\n                    console.error(\"No access token found in session.\")\n                    setStore({ authenticated: false, loaded: true })\n                }\n                */}else{console.error(\"No session found in localStorage\");setStore({authenticated:false,loaded:true});}},[]);return /*#__PURE__*/_jsx(Component,{...props});};}// Override for text elements to consume the fetched body content\nexport function applyFetchedContent(Component){return props=>{const[store]=useStore()// Access the store\n;return /*#__PURE__*/_jsx(Component,{...props,text:store.bodyContent});};}// Override for text elements to consume the fetched body content\nexport function isLoggedIn(Component){return props=>{const[store]=useStore()// Access the store\n;if(store.authenticated&&store.loaded){return /*#__PURE__*/_jsx(Component,{...props});}else{return null;}};}export function isLoggedOut(Component){return props=>{const[store]=useStore()// Access the store\n;if(!store.authenticated&&store.loaded){return /*#__PURE__*/_jsx(Component,{...props});}else{return null;}};}export function isLoading(Component){return props=>{const[store]=useStore()// Access the store\n;if(!store.loaded){return /*#__PURE__*/_jsx(Component,{...props});}else{return null;}};}\nexport const __FramerMetadata__ = {\"exports\":{\"withCheckAuth\":{\"type\":\"reactHoc\",\"name\":\"withCheckAuth\",\"annotations\":{\"framerContractVersion\":\"1\"}},\"isLoggedIn\":{\"type\":\"reactHoc\",\"name\":\"isLoggedIn\",\"annotations\":{\"framerContractVersion\":\"1\"}},\"isLoggedOut\":{\"type\":\"reactHoc\",\"name\":\"isLoggedOut\",\"annotations\":{\"framerContractVersion\":\"1\"}},\"isLoading\":{\"type\":\"reactHoc\",\"name\":\"isLoading\",\"annotations\":{\"framerContractVersion\":\"1\"}},\"applyFetchedContent\":{\"type\":\"reactHoc\",\"name\":\"applyFetchedContent\",\"annotations\":{\"framerContractVersion\":\"1\"}},\"__FramerMetadata__\":{\"type\":\"variable\"}}}\n//# sourceMappingURL=./Auth.map"],"mappings":"mLAA8E,SAAgB,EAAY,EAAO,CACjH,IAAM,EAAU,EAAK,CAAC,MAAM,OAAO,OAAO,CAAC,GAAG,EAAO,CAAC,CAAC,CAAC,CAClD,EAAa,GAAU,CAC1B,OAAO,GAAW,aAAY,EAAS,EAAS,EAAU,MAAM,EAAE,EAAU,MAAM,OAAO,OAAO,CAAC,GAAG,EAAU,MAAM,GAAG,EAAS,CAAC,EAChI,EAAW,OAAO,GAAS,SAAS,OAAO,OAAO,CAAC,GAAG,EAAO,CAAC,CAAC,EAC7D,EAAa,IAAI,IACjB,EAAc,GAAU,CAC3B,OAAO,GAAW,aAAY,EAAS,EAAS,EAAW,EAAE,EAAW,OAAO,GAAW,SAAS,OAA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