fix: proteccion estricta de sesion al cerrar sesion y redireccion limpia a landing page
This commit is contained in:
parent
50a76b534e
commit
d287a8f430
|
|
@ -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;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user