File size: 496 Bytes
803d869
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
import React from "react";
import { Navigate } from "react-router-dom";
import { useAuth } from "../../context/AuthContext";

const ProtectedRoute = ({ children }) => {
  const { authenticated, loading } = useAuth();

  if (loading) {
    return <div>Loading...</div>; // ✅ Wait until token check completes
  }

  if (!authenticated) {
    return <Navigate to="/login" state={{ from: window.location.pathname }} />;
  }

  return children;
};

export default ProtectedRoute;