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