Spaces:
Running
Running
| import React from 'react'; | |
| import { Navigate, Outlet } from 'react-router-dom'; | |
| import { useAuth } from '../contexts/AuthContext'; | |
| import { CircularProgress, Box } from '@mui/material'; | |
| const ProtectedRoute = () => { | |
| const { token, loading } = useAuth(); | |
| if (loading) { | |
| return ( | |
| <Box display="flex" justifyContent="center" alignItems="center" height="100vh"> | |
| <CircularProgress /> | |
| </Box> | |
| ); | |
| } | |
| return token ? <Outlet /> : <Navigate to="/login" />; | |
| }; | |
| export default ProtectedRoute; | |