Spaces:
Sleeping
Sleeping
Download frontend/src/components/ProtectedRoute.jsx from yamiclaws/auth-backend: direct link, hf CLI and curl.
- Browser
- Download file 1.05 kB
-
https://huggingface.co/spaces/yamiclaws/auth-backend/resolve/main/frontend/src/components/ProtectedRoute.jsx
- Command line
-
hf download hf://spaces/yamiclaws/auth-backend/frontend/src/components/ProtectedRoute.jsx
-
curl -L -o ProtectedRoute.jsx https://huggingface.co/spaces/yamiclaws/auth-backend/resolve/main/frontend/src/components/ProtectedRoute.jsx
1.05 kB
| import { Navigate } from "react-router-dom" | |
| import { useAuth } from "../context/AuthContext" | |
| export default function ProtectedRoute({ children }) { | |
| const { user, loading } = useAuth() | |
| if (loading) { | |
| return ( | |
| <div style={{ | |
| display: "flex", | |
| flexDirection: "column", | |
| alignItems: "center", | |
| justifyContent: "center", | |
| height: "80vh", | |
| gap: "1rem" | |
| }}> | |
| <div style={{ | |
| width: "40px", | |
| height: "40px", | |
| border: "4px solid rgba(255, 255, 255, 0.1)", | |
| borderTop: "4px solid var(--accent-color)", | |
| borderRadius: "50%", | |
| animation: "spin 1s linear infinite" | |
| }} /> | |
| <p style={{ color: "var(--text-secondary)", fontSize: "0.95rem" }}>Loading your session...</p> | |
| <style>{` | |
| @keyframes spin { | |
| 0% { transform: rotate(0deg); } | |
| 100% { transform: rotate(360deg); } | |
| } | |
| `}</style> | |
| </div> | |
| ) | |
| } | |
| return user ? children : <Navigate to="/login" replace /> | |
| } | |