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

17 lines
397 B
TypeScript
Raw Normal View History

2025-05-27 17:47:03 +00:00
import { JSX } from "react";
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 to='/login' replace />;
}
return children;
};