Spaces:
Sleeping
Sleeping
Download frontend/src/components/ProtectedRoute.jsx from habib-analyst/email-agent-api: direct link, hf CLI and curl.
- Browser
- Download file 1.03 kB
-
https://huggingface.co/spaces/habib-analyst/email-agent-api/resolve/main/frontend/src/components/ProtectedRoute.jsx
- Command line
-
hf download hf://spaces/habib-analyst/email-agent-api/frontend/src/components/ProtectedRoute.jsx
-
curl -L -o ProtectedRoute.jsx https://huggingface.co/spaces/habib-analyst/email-agent-api/resolve/main/frontend/src/components/ProtectedRoute.jsx
1.03 kB
| import { Loader2 } from "lucide-react"; | |
| import { useAuth } from "../context/AuthContext"; | |
| import { Navigate, useLocation } from "react-router-dom"; | |
| export default function ProtectedRoute({ children }) { | |
| const { authenticated, loading } = useAuth(); | |
| const location = useLocation(); | |
| if (loading) { | |
| return ( | |
| <div className="min-h-screen flex items-center justify-center bg-white dark:bg-[#0a0a0f] transition-colors duration-300"> | |
| <div className="relative z-10 flex flex-col items-center gap-4"> | |
| <div className="relative"> | |
| <div className="absolute inset-0 bg-indigo-500 rounded-full blur-xl opacity-20 animate-pulse" /> | |
| <Loader2 className="relative w-10 h-10 text-indigo-500 dark:text-indigo-400 animate-spin" /> | |
| </div> | |
| <p className="text-sm text-[var(--c-text-secondary)]">Loading...</p> | |
| </div> | |
| </div> | |
| ); | |
| } | |
| if (!authenticated) { | |
| return <Navigate to="/login" state={{ from: location }} replace />; | |
| } | |
| return children; | |
| } | |