/ frontend / src / app / auth / AuthGuard.jsx
AuthGuard.jsx
 1  import { Navigate, useLocation } from "react-router-dom";
 2  
 3  import useAuth from "app/hooks/useAuth";
 4  
 5  export default function AuthGuard({ children }) {
 6    const { isAuthenticated } = useAuth();
 7    const { pathname } = useLocation();
 8  
 9    if (isAuthenticated) return <>{children}</>;
10  
11    return <Navigate replace to="/login" state={{ from: pathname }} />;
12  }