Spaces:
Running
Running
Download frontend/src/components/ProtectedRoute.jsx from dimensionalpulsar/restaurante: direct link, hf CLI and curl.
- Browser
- Download file 585 Bytes
-
https://huggingface.co/spaces/dimensionalpulsar/restaurante/resolve/main/frontend/src/components/ProtectedRoute.jsx
- Command line
-
hf download hf://spaces/dimensionalpulsar/restaurante/frontend/src/components/ProtectedRoute.jsx
-
curl -L -o ProtectedRoute.jsx https://huggingface.co/spaces/dimensionalpulsar/restaurante/resolve/main/frontend/src/components/ProtectedRoute.jsx
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; | |
| } | |