16 lines
453 B
TypeScript
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}</>;
|
|
};
|