// this component is helping us to protect our routes so that only authenticated users can access the routes
import { Navigate } from 'react-router-dom';

// this function is firstly checking if the user is authenticated by checking the token in the localStorage
// if the user is not authenticated, it will redirect the user to the login page
// if the user is authenticated, it will return the children components
//and the children component is the component that we want to protect
function ProtectedRoute({ children }) {
  const token = localStorage.getItem('token');

  if (!token) {
    return <Navigate to="/login" replace />;
  }

  return children;
}

export default ProtectedRoute;
