{"version":3,"file":"RouteGuard.BSPtECaH.mjs","names":[],"sources":["https:/framerusercontent.com/modules/FR0ea85NzFqWgTJqsvZC/u0BLSuR2GEZYRvFOfV9i/RouteGuard.js"],"sourcesContent":["import{jsx as _jsx}from\"react/jsx-runtime\";import*as React from\"react\";import{addPropertyControls,ControlType}from\"framer\";const TOKEN_KEY=\"demo_api_token_v1\";const PROTECTED_ROUTES=[\"/my-workouts\",\"/my-account\"];const LOGIN_ROUTE=\"/login\";const DEFAULT_AUTHED_REDIRECT=\"/\";function hasToken(){if(typeof window===\"undefined\")return false;return!!localStorage.getItem(TOKEN_KEY);}export default function RouteGuard({enabled,debugDot}){React.useEffect(()=>{if(!enabled)return;if(typeof window===\"undefined\")return;const check=()=>{const path=window.location.pathname;const loggedIn=hasToken();// 1) não logado tentando acessar rota protegida\nif(!loggedIn&&PROTECTED_ROUTES.includes(path)){window.location.replace(LOGIN_ROUTE);return;}// 2) já logado tentando acessar /login\nif(loggedIn&&path===LOGIN_ROUTE){window.location.replace(DEFAULT_AUTHED_REDIRECT);return;}};// roda uma vez ao montar\ncheck();// roda quando auth mudar (logout/login) na mesma aba\nwindow.addEventListener(\"auth:changed\",check);// roda quando mudar em outra aba (storage event)\nwindow.addEventListener(\"storage\",check);return()=>{window.removeEventListener(\"auth:changed\",check);window.removeEventListener(\"storage\",check);};},[enabled]);// UI mínima 1x1px (invisível)\nreturn /*#__PURE__*/_jsx(\"div\",{style:{position:\"absolute\",width:1,height:1,left:0,top:0,opacity:debugDot?.5:0,pointerEvents:\"none\",background:debugDot?\"#ff00ff\":\"transparent\"}});}addPropertyControls(RouteGuard,{enabled:{type:ControlType.Boolean,title:\"Enabled\",defaultValue:true},debugDot:{type:ControlType.Boolean,title:\"Debug Dot\",defaultValue:false}});\nexport const __FramerMetadata__ = {\"exports\":{\"default\":{\"type\":\"reactComponent\",\"name\":\"RouteGuard\",\"slots\":[],\"annotations\":{\"framerContractVersion\":\"1\"}},\"__FramerMetadata__\":{\"type\":\"variable\"}}}\n//# sourceMappingURL=./RouteGuard.map"],"mappings":"wLAAkR,SAAS,GAAU,CAA6C,OAAlC,IAAS,OAAmB,GAAY,CAAC,CAAC,aAAa,QAAQ,EAAU,CAAE,SAAwB,EAAW,CAAC,UAAQ,YAAU,CAMjb,OANkb,MAAoB,CAAoB,GAAhB,CAAC,GAAyB,IAAS,OAAY,OAAO,IAAM,MAAU,CAAC,IAAM,EAAK,EAAO,SAAS,SAAe,EAAS,GAAU,CAC9kB,GAAG,CAAC,GAAU,EAAiB,SAAS,EAAK,CAAC,CAAC,EAAO,SAAS,QAAQ,EAAY,CAAC,OACpF,GAAG,GAAU,IAAO,EAAY,CAAC,EAAO,SAAS,QAAQ,EAAwB,CAAC,SAGzC,OAFzC,GAAO,CACP,EAAO,iBAAiB,eAAe,EAAM,CAC7C,EAAO,iBAAiB,UAAU,EAAM,KAAW,CAAC,EAAO,oBAAoB,eAAe,EAAM,CAAC,EAAO,oBAAoB,UAAU,EAAM,GAAK,CAAC,EAAQ,CAAC,CAC3I,EAAK,MAAM,CAAC,MAAM,CAAC,SAAS,WAAW,MAAM,EAAE,OAAO,EAAE,KAAK,EAAE,IAAI,EAAE,QAAQ,EAAS,GAAG,EAAE,cAAc,OAAO,WAAW,EAAS,UAAU,cAAc,CAAC,CAAC,8BANvI,IAA4B,IAAoD,CAAM,EAAU,oBAA0B,EAAiB,CAAC,eAAe,cAAc,CAAO,EAAY,SAAe,EAAwB,IAM1F,EAAoB,EAAW,CAAC,QAAQ,CAAC,KAAK,EAAY,QAAQ,MAAM,UAAU,aAAa,GAAK,CAAC,SAAS,CAAC,KAAK,EAAY,QAAQ,MAAM,YAAY,aAAa,GAAM,CAAC,CAAC"}