15 lines
391 B
TypeScript
15 lines
391 B
TypeScript
import React from "react";
|
|
import { Navigate, Outlet, useLocation } from "react-router-dom";
|
|
import { useAuth } from "../contexts/AuthContext";
|
|
|
|
export const PrivateRoute: React.FC = () => {
|
|
const { isAuthenticated } = useAuth();
|
|
const location = useLocation();
|
|
|
|
return isAuthenticated ? (
|
|
<Outlet />
|
|
) : (
|
|
<Navigate to="/login" state={{ from: location }} replace />
|
|
);
|
|
};
|