import React from "react";
import { Navigate } from "react-router-dom";

const ProtectedRoute = ({ children, allowedRoles, userRole }) => {
  const isAuthenticated = !!localStorage.getItem('token'); // Mengecek token
    
  // return isAuthenticated ? children : <Navigate to="/login" />;

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

  if (allowedRoles && allowedRoles.includes(userRole)) {
    return <Navigate to="/" replace />;
  }

  return children;
};



export default ProtectedRoute;
