import { useSelector } from 'react-redux';
import { Navigate } from 'react-router-dom';

const ProtectedRoute = ({ children }) => {
  // Check if user is authenticated using Redux state
  const authState = useSelector((state) => state.auth);
  const isAuthenticated = authState?.isAuthenticated || authState?.token;

  if (!isAuthenticated) {
    // Redirect to login page if not authenticated
    return <Navigate to="/signin" replace />;
  }

  // If authenticated, render the protected component
  return children;
};

export default ProtectedRoute; 