{"version":3,"file":"AuthOverrides.DcIZ6Lay.mjs","names":["useCallback","useState","useRef"],"sources":["https:/cdn.jsdelivr.net/npm/jwt-decode@4.0.0/build/esm/index.js","https:/framerusercontent.com/modules/b1CQP9WkgPUviCX02hnj/Hk5LE2Vr77rTIg2XRSkY/AuthOverrides.js"],"sourcesContent":["export class InvalidTokenError extends Error {\n}\nInvalidTokenError.prototype.name = \"InvalidTokenError\";\nfunction b64DecodeUnicode(str) {\n    return decodeURIComponent(atob(str).replace(/(.)/g, (m, p) => {\n        let code = p.charCodeAt(0).toString(16).toUpperCase();\n        if (code.length < 2) {\n            code = \"0\" + code;\n        }\n        return \"%\" + code;\n    }));\n}\nfunction base64UrlDecode(str) {\n    let output = str.replace(/-/g, \"+\").replace(/_/g, \"/\");\n    switch (output.length % 4) {\n        case 0:\n            break;\n        case 2:\n            output += \"==\";\n            break;\n        case 3:\n            output += \"=\";\n            break;\n        default:\n            throw new Error(\"base64 string is not of the correct length\");\n    }\n    try {\n        return b64DecodeUnicode(output);\n    }\n    catch (err) {\n        return atob(output);\n    }\n}\nexport function jwtDecode(token, options) {\n    if (typeof token !== \"string\") {\n        throw new InvalidTokenError(\"Invalid token specified: must be a string\");\n    }\n    options || (options = {});\n    const pos = options.header === true ? 0 : 1;\n    const part = token.split(\".\")[pos];\n    if (typeof part !== \"string\") {\n        throw new InvalidTokenError(`Invalid token specified: missing part #${pos + 1}`);\n    }\n    let decoded;\n    try {\n        decoded = base64UrlDecode(part);\n    }\n    catch (e) {\n        throw new InvalidTokenError(`Invalid token specified: invalid base64 for part #${pos + 1} (${e.message})`);\n    }\n    try {\n        return JSON.parse(decoded);\n    }\n    catch (e) {\n        throw new InvalidTokenError(`Invalid token specified: invalid json for part #${pos + 1} (${e.message})`);\n    }\n}\n","import{jsx as _jsx}from\"react/jsx-runtime\";import{forwardRef,useEffect,useState,useMemo,useRef,useCallback,startTransition}from\"react\";// @ts-ignore\nimport{useRouter,useTracking}from\"framer\";import{jwtDecode}from\"https://cdn.jsdelivr.net/npm/jwt-decode@4.0.0/build/esm/index.js\";import{createStore}from\"https://framer.com/m/framer/store.js@^1.0.0\";import{apiCall}from\"https://framerusercontent.com/modules/7UNuLANdDiCpMDZPIN74/tGQcrjHipT9BKAANm5fx/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 track=useTracking();const handleClick=()=>{setStore({...EMPTY_STORE,authLoaded:true});clearStorage();track(\"logout\");};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 setStore=value=>{setTimeout(()=>{_setStore(value);},50);};const router=useRouter();const requestRefresh=useCallback(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();sendLoadedEvent();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}});sendLoadedEvent(true);}catch{setStore({...EMPTY_STORE,authLoaded:true});clearStorage();sendLoadedEvent();}},[setStore]);// Refresh token before expiration\nuseEffect(()=>{if(!store?.accessToken||!store?.refreshToken)return;try{const decoded=jwtDecode(store.accessToken);const expiresAt=decoded.exp*1e3;const refreshAt=expiresAt-6e4// 1 minute early\n;const delay=refreshAt-Date.now();const timeout=setTimeout(()=>{requestRefresh(store?.refreshToken);},Math.max(0,delay));return()=>clearTimeout(timeout);}catch{// Clear storage and context\n}},[store]);// Return path saving\nconst savePathname=(exceptions=[])=>{const pathname=window.location.pathname;if(pathname===\"/\"){localStorage.removeItem(\"lastPathname\");return;}if(exceptions.includes(pathname)){return;}localStorage.setItem(\"lastPathname\",pathname);};const sendLoadedEvent=(loggedIn=false)=>{if(!window)return;window.dispatchEvent(new CustomEvent(\"auth-loaded\",{detail:{isAuthenticated:loggedIn}}));};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});sendLoadedEvent();}},[]);return /*#__PURE__*/_jsx(Component,{ref:ref,...props});});}export function withShowToCreatorOnly(Component){return /*#__PURE__*/forwardRef((props,ref)=>{const[store,setStore]=useStore();const[visible,setVisisble]=useState(false);const mainRef=useRef(null);const parentOriginalDisplay=useRef(null);const initialSet=useRef(false);const getSlug=()=>{if(!window?.location||window.location.pathname.split(\"/\").length===1)return null;return window.location.pathname.split(\"/\").reverse()[0];};const fetchOwnership=useCallback(async slug=>{try{const resp=await apiCall(`/api/problems/by-slug/${slug}/owned`,\"GET\",undefined,store.accessToken);startTransition(()=>{setVisisble(resp?.isOwner);});}catch{startTransition(()=>{setVisisble(false);});}},[store.accessToken]);useEffect(()=>{const slug=getSlug();if(slug){if(store?.accessToken){fetchOwnership(slug);}else{startTransition(()=>{setVisisble(false);});}}return()=>{};},[fetchOwnership]);return /*#__PURE__*/_jsx(Component,{ref:mainRef,...props,style:{...props?.style||{},...visible?{}:{display:\"none\"}}});});}\nexport const __FramerMetadata__ = {\"exports\":{\"withJoin\":{\"type\":\"reactHoc\",\"name\":\"withJoin\",\"annotations\":{\"framerContractVersion\":\"1\"}},\"saveStorage\":{\"type\":\"function\",\"annotations\":{\"framerContractVersion\":\"1\"}},\"clearStorage\":{\"type\":\"function\",\"annotations\":{\"framerContractVersion\":\"1\"}},\"useStore\":{\"type\":\"variable\",\"annotations\":{\"framerContractVersion\":\"1\"}},\"UserData\":{\"type\":\"tsType\",\"annotations\":{\"framerContractVersion\":\"1\"}},\"EMPTY_STORE\":{\"type\":\"variable\",\"annotations\":{\"framerContractVersion\":\"1\"}},\"withInitAuth\":{\"type\":\"reactHoc\",\"name\":\"withInitAuth\",\"annotations\":{\"framerContractVersion\":\"1\"}},\"withLogout\":{\"type\":\"reactHoc\",\"name\":\"withLogout\",\"annotations\":{\"framerContractVersion\":\"1\"}},\"withShowToCreatorOnly\":{\"type\":\"reactHoc\",\"name\":\"withShowToCreatorOnly\",\"annotations\":{\"framerContractVersion\":\"1\"}},\"StoreType\":{\"type\":\"tsType\",\"annotations\":{\"framerContractVersion\":\"1\"}},\"withAuthMe\":{\"type\":\"reactHoc\",\"name\":\"withAuthMe\",\"annotations\":{\"framerContractVersion\":\"1\"}},\"__FramerMetadata__\":{\"type\":\"variable\"}}}"],"mappings":"sUAGA,SAAS,EAAiB,EAAK,CAC3B,OAAO,mBAAmB,KAAK,CAAG,CAAC,CAAC,QAAQ,QAAS,EAAG,IAAM,CAC1D,IAAI,EAAO,EAAE,WAAW,CAAC,CAAC,CAAC,SAAS,EAAE,CAAC,CAAC,YAAY,EAIpD,OAHI,EAAK,OAAS,IACd,EAAO,IAAM,GAEV,IAAM,CACjB,CAAC,CAAC,CACN,CACA,SAAS,EAAgB,EAAK,CAC1B,IAAI,EAAS,EAAI,QAAQ,KAAM,GAAG,CAAC,CAAC,QAAQ,KAAM,GAAG,EACrD,OAAQ,EAAO,OAAS,EAAxB,CACI,IAAK,GACD,MACJ,IAAK,GACD,GAAU,KACV,MACJ,IAAK,GACD,GAAU,IACV,MACJ,QACI,MAAU,MAAM,4CAA4C,CACpE,CACA,GAAI,CACA,OAAO,EAAiB,CAAM,CAClC,MACY,CACR,OAAO,KAAK,CAAM,CACtB,CACJ,CACA,SAAgB,EAAU,EAAO,EAAS,CACtC,GAAI,OAAO,GAAU,SACjB,MAAM,IAAI,EAAkB,2CAA2C,EAE3E,AAAY,IAAU,CAAC,EACvB,IAAM,EAAM,EAAQ,SAAW,GAAO,EAAI,EACpC,EAAO,EAAM,MAAM,G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