{"version":3,"file":"AuthOverrides.ujkK7LPc.mjs","names":["useRef","useState","useMemo"],"sources":["https:/framerusercontent.com/modules/490iqhJn8toy1kxvHz3t/8uRq14wsgwXncY2ABtLA/AuthOverrides.js"],"sourcesContent":["import{jsx as _jsx}from\"react/jsx-runtime\";import{forwardRef,useEffect,useState,useMemo,useRef}from\"react\";// @ts-ignore\nimport{useRouter}from\"framer\";import{createStore}from\"https://framer.com/m/framer/store.js@^1.0.0\";import{apiCall}from\"https://framerusercontent.com/modules/5qNETUptUrBVKb9Exiz2/iQQsMdWwLbilnnVFq7MW/Utils.js\";export const EMPTY_STORE={authLoaded:false,isAuthenticated:false,accessToken:null,refreshToken:null,userData:null};export const useStore=createStore(EMPTY_STORE);/*\n    Helpers\n*/const AUTH_GUARD_VARIANT=loggedIn=>loggedIn?\"Logged In\":\"Logged Out\";function loadStorage(){const accessToken=localStorage.getItem(\"accessToken\");const refreshToken=localStorage.getItem(\"refreshToken\");return{accessToken:accessToken||null,refreshToken:refreshToken||null};}export function saveStorage(newValue){localStorage.setItem(\"accessToken\",newValue.accessToken);localStorage.setItem(\"refreshToken\",newValue.refreshToken);}export function clearStorage(){localStorage.removeItem(\"accessToken\");localStorage.removeItem(\"refreshToken\");}/*\n    Overrides\n*/export function withAuthMe(Component){return /*#__PURE__*/forwardRef((props,ref)=>{const[store]=useStore();return /*#__PURE__*/_jsx(Component,{ref:ref,...props,firstName:store?.userData?.firstName||\"\",lastName:store?.userData?.lastName||\"\",email:store?.userData?.email||\"\",loggedIn:store.isAuthenticated});});}export function withLogout(Component){return /*#__PURE__*/forwardRef((props,ref)=>{const[store,setStore]=useStore();const handleClick=()=>{setStore({...EMPTY_STORE,authLoaded:true});clearStorage();};return /*#__PURE__*/_jsx(Component,{ref:ref,...props,onClick:handleClick});});}export function withJoin(Component){return /*#__PURE__*/forwardRef((props,ref)=>{const[store]=useStore();const storeRef=useRef(store);useEffect(()=>{storeRef.current=store;},[store]);const[joinedSlugs,setJoinedSlugs]=useState([]);const handleRefetch=()=>{if(storeRef.current.authLoaded&&storeRef.current.isAuthenticated){fetchJoinedSlugs();}};const fetchJoinedSlugs=async()=>{try{const resp=await apiCall(\"/api/problems/my-slugs\",\"GET\",undefined,storeRef.current.accessToken);if(!resp.slugs){setJoinedSlugs([]);return;}setJoinedSlugs(resp.slugs);}catch{setJoinedSlugs([]);return;}};const isCurrentJoined=useMemo(()=>{if(!window||!joinedSlugs)return false;const slug=window.location.pathname.split(\"/\").reverse()?.[0];return joinedSlugs.includes(slug);},[joinedSlugs,window?.location]);useEffect(()=>{if(store.authLoaded&&store.isAuthenticated){fetchJoinedSlugs();}},[store]);// Refetch trigger\nuseEffect(()=>{if(!window)return;window.addEventListener(\"user-joined\",handleRefetch);return()=>{window.removeEventListener(\"user-joined\",handleRefetch);};},[]);return /*#__PURE__*/_jsx(Component,{ref:ref,...props,loggedIn:store.isAuthenticated,isJoined:isCurrentJoined});});}export function withInitAuth(Component){return /*#__PURE__*/forwardRef((props,ref)=>{const[store,setStore]=useStore();const router=useRouter();const requestRefresh=async refreshToken=>{try{const resp=await apiCall(\"/api/refresh-token\",\"POST\",{refreshToken});if(resp.error||!resp.token||!resp.refreshToken){setStore({...EMPTY_STORE,authLoaded:true});clearStorage();return;}saveStorage({accessToken:resp.token,refreshToken:resp.refreshToken});setStore({authLoaded:true,isAuthenticated:true,accessToken:resp.token,refreshToken:resp.refreshToken,userData:{firstName:resp.firstName,lastName:resp.lastName,email:resp.email,userId:resp.userId}});}catch{setStore({...EMPTY_STORE,authLoaded:true});clearStorage();}};const savePathname=(exceptions=[])=>{const pathname=window.location.pathname;if(pathname===\"/\"){localStorage.removeItem(\"lastPathname\");return;}if(exceptions.includes(pathname)){return;}localStorage.setItem(\"lastPathname\",pathname);};useEffect(()=>{if(!window)return;savePathname([\"/bejelentkezes\",\"/confirm\",\"/\"]);},[router?.currentRouteId]);// Initial loading\nuseEffect(()=>{const storage=loadStorage();// Load auth\nif(storage.refreshToken){requestRefresh(storage.refreshToken);}else{setStore({...EMPTY_STORE,authLoaded:true});}},[]);return /*#__PURE__*/_jsx(Component,{ref:ref,...props});});}export function withResendVerify(Component){return /*#__PURE__*/forwardRef((props,ref)=>{const[cooldownTime,setCooldownTime]=useState(30);const cooldownTimeRef=useRef(cooldownTime);useEffect(()=>{cooldownTimeRef.current=cooldownTime;},[cooldownTime]);const tickTimer=()=>{if(cooldownTimeRef.current>0){setCooldownTime(cooldownTimeRef.current-1);}};const handleClick=()=>{if(!window||cooldownTimeRef.current!==0)return;window.dispatchEvent(new CustomEvent(\"user-resend\"));};useEffect(()=>{const timerInterval=setInterval(()=>{tickTimer();},1e3);return()=>{clearInterval(timerInterval);};},[]);const correctedProps=useMemo(()=>{if(cooldownTime===0){// Set to default\nreturn props;}return{...props,c_m:`${props[\"c_m\"]} (El\\xe9hető ${cooldownTime} mp m\\xfalva.)`};},[cooldownTime]);return /*#__PURE__*/_jsx(Component,{ref:ref,...correctedProps,onClick:handleClick});});}\nexport const __FramerMetadata__ = {\"exports\":{\"saveStorage\":{\"type\":\"function\",\"annotations\":{\"framerContractVersion\":\"1\"}},\"withLogout\":{\"type\":\"reactHoc\",\"name\":\"withLogout\",\"annotations\":{\"framerContractVersion\":\"1\"}},\"EMPTY_STORE\":{\"type\":\"variable\",\"annotations\":{\"framerContractVersion\":\"1\"}},\"withAuthMe\":{\"type\":\"reactHoc\",\"name\":\"withAuthMe\",\"annotations\":{\"framerContractVersion\":\"1\"}},\"clearStorage\":{\"type\":\"function\",\"annotations\":{\"framerContractVersion\":\"1\"}},\"withJoin\":{\"type\":\"reactHoc\",\"name\":\"withJoin\",\"annotations\":{\"framerContractVersion\":\"1\"}},\"withInitAuth\":{\"type\":\"reactHoc\",\"name\":\"withInitAuth\",\"annotations\":{\"framerContractVersion\":\"1\"}},\"withResendVerify\":{\"type\":\"reactHoc\",\"name\":\"withResendVerify\",\"annotations\":{\"framerContractVersion\":\"1\"}},\"StoreType\":{\"type\":\"tsType\",\"annotations\":{\"framerContractVersion\":\"1\"}},\"UserData\":{\"type\":\"tsType\",\"annotations\":{\"framerContractVersion\":\"1\"}},\"useStore\":{\"type\":\"variable\",\"annotations\":{\"framerContractVersion\":\"1\"}},\"__FramerMetadata__\":{\"type\":\"variable\"}}}"],"mappings":"uTAGuE,SAAS,GAAa,CAAC,IAAM,EAAY,aAAa,QAAQ,cAAc,CAAO,EAAa,aAAa,QAAQ,eAAe,CAAC,MAAM,CAAC,YAAY,GAAa,KAAK,aAAa,GAAc,KAAK,CAAE,SAAgB,EAAY,EAAS,CAAC,aAAa,QAAQ,cAAc,EAAS,YAAY,CAAC,aAAa,QAAQ,eAAe,EAAS,aAAa,CAAE,SAAgB,GAAc,CAAC,aAAa,WAAW,cAAc,CAAC,aAAa,WAAW,eAAe,CAEzhB,SAAgB,EAAW,EAAU,CAAC,OAAoB,GAAY,EAAM,IAAM,CAAC,GAAK,CAAC,GAAO,GAAU,CAAC,OAAoB,EAAK,EAAU,CAAK,MAAI,GAAG,EAAM,UAAU,GAAO,UAAU,WAAW,GAAG,SAAS,GAAO,UAAU,UAAU,GAAG,MAAM,GAAO,UAAU,OAAO,GAAG,SAAS,EAAM,gBAAgB,CAAC,EAAG,CAAE,SAAgB,EAAW,EAAU,CAAC,OAAoB,GAAY,EAAM,IAAM,CAAC,GAAK,CAAC,EAAM,GAAU,GAAU,CAAO,MAAgB,CAAC,EAAS,CAAC,GAAG,EAAY,WAAW,GAAK,CAAC,CAAC,GAAc,EAAG,OAAoB,EAAK,EAAU,CAAK,MAAI,GAAG,EAAM,QAAQ,EAAY,CAAC,EAAG,CAAE,SAAgB,EAAS,EAAU,CAAC,OAAoB,GAAY,EAAM,IAAM,CAAC,GAAK,CAAC,GAAO,GAAU,CAAO,EAASA,EAAO,EAAM,CAAC,MAAc,CAAC,EAAS,QAAQ,GAAQ,CAAC,EAAM,CAAC,CAAC,GAAK,CAAC,EAAY,GAAgBC,EAAS,EAAE,CAAC,CAAO,MAAkB,CAAI,EAAS,QAAQ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