{"version":3,"file":"UserAuth.D9ufk6UT.mjs","names":["useState"],"sources":["https:/framerusercontent.com/modules/kbBpzy5CAvlp5a5qWe7x/Gnr9kccBKQLt1K607VK3/UserAuth.js"],"sourcesContent":["import{jsx as _jsx}from\"react/jsx-runtime\";import{forwardRef,useEffect,useState}from\"react\";let currentAuthState=\"loading\";let authRequestStarted=false;const authListeners=new Set;function setAuthState(state){currentAuthState=state;authListeners.forEach(listener=>listener());}async function checkAuthentication(){if(authRequestStarted)return;authRequestStarted=true;const controller=new AbortController;const timeout=window.setTimeout(()=>controller.abort(),1e4);try{const response=await fetch(\"https://api2-prod.watermelon.ai/iam/v1/verify_cookie\",{method:\"POST\",headers:{\"Content-Type\":\"application/json\"},credentials:\"include\",cache:\"no-store\",signal:controller.signal});if(!response.ok){setAuthState(\"anonymous\");return;}const data=await response.json();setAuthState(data?.verified===true?\"authenticated\":\"anonymous\");}catch(error){console.error(\"Authentication check failed:\",error);setAuthState(\"anonymous\");}finally{window.clearTimeout(timeout);}}function useAuthentication(){const[authState,updateState]=useState(\"loading\");useEffect(()=>{const syncState=()=>updateState(currentAuthState);authListeners.add(syncState);syncState();void checkAuthentication();return()=>{authListeners.delete(syncState);};},[]);return authState;}// Show Log in and other guest-only layers.\n// They remain visible while authentication is loading.\nexport function GuestOnly(Component){return /*#__PURE__*/forwardRef(function GuestOnlyOverride(props,ref){const authState=useAuthentication();if(authState===\"authenticated\")return null;return /*#__PURE__*/_jsx(Component,{...props,ref:ref});});}// Show layers only after authentication succeeds.\nexport function AuthenticatedOnly(Component){return /*#__PURE__*/forwardRef(function AuthenticatedOnlyOverride(props,ref){const authState=useAuthentication();if(authState!==\"authenticated\")return null;return /*#__PURE__*/_jsx(Component,{...props,ref:ref});});}// Keep the original CTA for guests; show Dashboard when authenticated.\nexport function AuthCTA(Component){return /*#__PURE__*/forwardRef(function AuthCTAOverride(props,ref){const authState=useAuthentication();if(authState===\"authenticated\"){return /*#__PURE__*/_jsx(Component,{...props,ref:ref,title:\"Dashboard\",link:\"https://app.watermelon.ai/\"});}return /*#__PURE__*/_jsx(Component,{...props,ref:ref});});}\nexport const __FramerMetadata__ = {\"exports\":{\"AuthCTA\":{\"type\":\"reactHoc\",\"name\":\"AuthCTA\",\"annotations\":{\"framerContractVersion\":\"1\"}},\"GuestOnly\":{\"type\":\"reactHoc\",\"name\":\"GuestOnly\",\"annotations\":{\"framerContractVersion\":\"1\"}},\"AuthenticatedOnly\":{\"type\":\"reactHoc\",\"name\":\"AuthenticatedOnly\",\"annotations\":{\"framerContractVersion\":\"1\"}},\"__FramerMetadata__\":{\"type\":\"variable\"}}}\n//# sourceMappingURL=./UserAuth.map"],"mappings":"8IAAoL,SAAS,EAAa,EAAM,CAAC,EAAiB,EAAM,EAAc,QAAQ,GAAU,EAAS,CAAC,CAAE,CAAC,eAAe,GAAqB,CAAC,GAAG,EAAmB,OAAO,EAAmB,GAAK,IAAM,EAAW,IAAI,gBAAsB,EAAQ,EAAO,eAAe,EAAW,MAAM,EAAE,GAAG,EAAE,GAAG,CAAC,IAAM,EAAS,MAAM,MAAM,uDAAuD,CAAC,OAAO,OAAO,QAAQ,CAAC,eAAe,kBAAkB,EAAE,YAAY,UAAU,MAAM,WAAW,OAAO,EAAW,MAAM,CAAC,EAAE,GAAG,CAAC,EAAS,GAAG,CAAC,EAAa,WAAW,EAAE,MAAO,CAAkC,GAAa,MAA7B,EAAS,KAAK,EAAA,EAAqB,WAAW,GAAK,gBAAgB,WAAW,CAAE,OAAO,EAAM,CAAC,QAAQ,MAAM,+BAA+B,CAAK,EAAE,EAAa,WAAW,CAAE,QAAQ,CAAC,EAAO,aAAa,CAAO,CAAE,CAAC,CAAC,SAAS,GAAmB,CAAC,GAAK,CAAC,EAAU,GAAaA,EAAS,SAAS,EAA0L,OAAxL,MAAc,CAAC,IAAM,MAAc,EAAY,CAAgB,EAAsE,OAApE,EAAc,IAAI,CAAS,EAAE,EAAU,EAAE,EAAyB,MAAY,CAAC,EAAc,OAAO,CAAS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