xtablo-source/ui/src/components/ProtectedRoute.tsx
2025-03-26 21:21:18 +01:00

16 lines
453 B
TypeScript

import { ReactNode } from "react";
import { useSession } from "../contexts/SessionContext";
import { Navigate } from "react-router-dom";
interface ProtectedRouteProps {
children: ReactNode;
}
export const ProtectedRoute = ({ children }: ProtectedRouteProps) => {
const { session } = useSession();
if (!session) {
return <Navigate to="/login" replace />;
}
// If authenticated, render the protected component
return <>{children}</>;
};