FactuGES_ERP/modules/auth/src/web/components/auth-guard.tsx

18 lines
403 B
TypeScript
Raw Normal View History

import type { JSX } from "react";
2025-05-27 17:47:03 +00:00
import { Navigate } from "react-router-dom";
2025-05-28 14:21:09 +00:00
import { useIsAuthenticated } from "../hooks";
2025-05-27 17:47:03 +00:00
/**
* Protege una ruta para usuarios autenticados.
*/
export const AuthGuard = ({ children }: { children: JSX.Element }) => {
2025-05-28 14:21:09 +00:00
const isAuthenticated = useIsAuthenticated();
2025-05-27 17:47:03 +00:00
if (!isAuthenticated) {
return <Navigate replace to="/login" />;
2025-05-27 17:47:03 +00:00
}
return children;
};