PageSourceSearch

https://live-menu.vercel.app/assets/useRoleRedirect-BFXktH4R.js

js live-menu.vercel.app collected 2026-10-03 07:14:54 UTC 2,792 bytes, 1 lines download raw bytes

1import{Q as T,H as U,u as x,r as s,s as o}from"./index-jGBnbQC-.js";function I(O={}){const{autoRedirect:g=!0,showSelectorOnMultiple:b=!0}=O,{user:n,loading:u}=T(),{userRestaurants:R,loading:d}=U(),p=x(),[c,w]=s.useState([]),[q,S]=s.useState(!1),[m,C]=s.useState(!1),[f,h]=s.useState(!1),_=s.useCallback(async t=>{const e=t||n?.id;if(!e)return[];const r=[];try{const{data:i}=await o.rpc("get_user_role",{p_user_id:e});if(i==="super_admin"||i==="platform_staff"){const a=i==="super_admin";r.push({type:a?"super_admin":"platform_staff",label:a?"Super Administrador":"Staff de Plataforma",description:a?"Acceso completo a toda la plataforma":"Gestión de operaciones de la plataforma",path:"/platform-admin"})}const{data:l}=await o.from("country_admins").select("country").eq("user_id",e),k=l&&l.length>0;k&&r.push({type:"country_admin",label:"Líder de Unidad Comercial",description:"Gestiona operadores, restaurantes y permisos de tu unidad comercial",countries:l.map(a=>a.country),path:"/platform-admin"});const{data:D}=await o.rpc("is_local_operator",{check_user_id:e});if(D){const{data:a}=await o.from("local_operators").select("territory_name, country").eq("user_id",e).eq("status","active");r.push({type:"local_operator",label:"Operador Local",description:"Capta restaurantes y gestiona tu red de afiliados",territories:a?.map(L=>({name:L.territory_name,country:L.country}))||[],path:"/operator-dashboard"})}else k&&r.push({type:"local_operator",label:"Operador Local",description:"Capta restaurantes y gestiona tu red de afiliados",territories:l.map(a=>({name:a.country,country:a.country})),path:"/operator-dashboard"});const{data:E}=await o.from("brand_users").select("brand_id").eq("user_id",e).limit(1).maybeSingle();E&&r.push({type:"brand_manager",label:"Administrador de Marca",description:"Gestiona campañas publicitarias y métricas de tu marca",path:"/brand-dashboard"});const A=R.length>0;let v=!1;if(!A){const{data:a}=await o.rpc("get_user_restaurant",{p_user_id:e});v=!!a}return(A||v)&&r.push({type:"restaurant_owner",label:"Dueño de Restaurante",description:"Administra tu menú, promociones y configuración",path:"/admin"}),r}catch(i){return console.error("Error verificando roles:",i),r}},[n,R]),y=s.useCallback(t=>{const e=t||c;e.length!==0&&(e.length===1?p(e[0].path):b?(w(e),S(!0)):p(e[0].path))},[c,p,b]);return s.useEffect(()=>{if(u||d||!n||m||f)return;h(!0);let t;return(async()=>{t=setTimeout(()=>{console.warn("Role check timed out after 10s"),h(!1),C(!0)},1e4);const e=await _();clearTimeout(t),w(e),C(!0),h(!1),g&&e.length>0&&y(e)})(),()=>{t&&clearTimeout(t)}},[n,u,d,m,f,_,g,y]),{availableRoles:c,showRoleSelector:q,setShowRoleSelector:S,loading:u||d||f,checked:m,userEmail:n?.email||"",hasRoles:c.length>0,checkRoles:_,redirectBasedOnRoles:y}}export{I as u};

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.