restaurante / src /components /ProtectedRoute.jsx
dimensionalpulsar's picture
Upload 47 files
564baf9 verified
raw
history blame contribute delete
585 Bytes
import React from 'react';
import { Navigate } from 'react-router-dom';
import { useAuth } from '../context/AuthContext';
export default function ProtectedRoute({ children, allowedRoles }) {
const { currentUser, userRole, loading } = useAuth();
if (loading) return <div className="app-container" style={{justifyContent:'center', alignItems:'center'}}>Cargando...</div>;
if (!currentUser) {
return <Navigate to="/login" replace />;
}
if (allowedRoles && !allowedRoles.includes(userRole)) {
return <Navigate to="/unauthorized" replace />;
}
return children;
}