From d287a8f430a7bbf21ac416ff3bcebfc8030c4df9 Mon Sep 17 00:00:00 2001 From: Javi_Desktop Date: Wed, 19 Aug 2026 18:43:40 -0300 Subject: [PATCH] fix: proteccion estricta de sesion al cerrar sesion y redireccion limpia a landing page --- frontend/src/App.jsx | 9 ++++++ .../src/components/layout/DashboardLayout.jsx | 28 ++++++++++++++++--- 2 files changed, 33 insertions(+), 4 deletions(-) diff --git a/frontend/src/App.jsx b/frontend/src/App.jsx index 93ce7a0..cb1d404 100644 --- a/frontend/src/App.jsx +++ b/frontend/src/App.jsx @@ -34,12 +34,21 @@ export default function App() { const pathname = window.location.pathname; if (hostname.includes("repairit.cloud")) { + const token = localStorage.getItem("repairit_token"); // Si está en el dashboard pero no en app.repairit.cloud, redirigir a app.repairit.cloud/dashboard if (hostname !== "app.repairit.cloud" && pathname.startsWith("/dashboard")) { + if (!token) { + window.location.href = "https://repairit.cloud/login"; + return; + } window.location.href = `https://app.repairit.cloud${pathname}`; return; } if (hostname === "app.repairit.cloud" && pathname === "/") { + if (!token) { + window.location.href = "https://repairit.cloud/login"; + return; + } window.location.href = "/dashboard"; return; } diff --git a/frontend/src/components/layout/DashboardLayout.jsx b/frontend/src/components/layout/DashboardLayout.jsx index 82b4ea5..0305c75 100644 --- a/frontend/src/components/layout/DashboardLayout.jsx +++ b/frontend/src/components/layout/DashboardLayout.jsx @@ -59,6 +59,16 @@ export default function DashboardLayout() { const [activeVenue, setActiveVenue] = useState(null); useEffect(() => { + const token = localStorage.getItem("repairit_token"); + if (!token) { + if (window.location.hostname.includes("repairit.cloud")) { + window.location.href = "https://repairit.cloud/login"; + } else { + navigate("/login"); + } + return; + } + if (!isSuperAdmin) { const loadVenues = async () => { try { @@ -88,10 +98,20 @@ export default function DashboardLayout() { } }; - const handleLogout = () => { - api.auth.logout(); - toast.success("Sesión cerrada correctamente."); - navigate("/"); + const handleLogout = async () => { + try { + await api.auth.logout(); + toast.success("Sesión cerrada correctamente."); + } catch (err) { + console.error("Error al cerrar sesión:", err); + } finally { + localStorage.clear(); + if (window.location.hostname.includes("repairit.cloud")) { + window.location.href = "https://repairit.cloud"; + } else { + window.location.href = "/"; + } + } }; // Determinar los Breadcrumbs basados en la ruta actual