10 lines
394 B
TypeScript
10 lines
394 B
TypeScript
import { Navigate, useLocation } from "react-router-dom";
|
|
import { useAuthContext } from "../hooks/AuthContext";
|
|
|
|
export function ProtectedRoute({ children }: { children: React.ReactNode }) {
|
|
const { isAuthenticated } = useAuthContext();
|
|
const location = useLocation();
|
|
if (!isAuthenticated) return <Navigate to="/login" state={{ from: location }} replace />;
|
|
return <>{children}</>;
|
|
}
|