Spaces:
Runtime error
Runtime error
Download apps/desktop/src/components/ProtectedRoute.tsx from erdoganpeker/hasari-api: direct link, hf CLI and curl.
- Browser
- Download file 622 Bytes
-
https://huggingface.co/spaces/erdoganpeker/hasari-api/resolve/main/apps/desktop/src/components/ProtectedRoute.tsx
- Command line
-
hf download hf://spaces/erdoganpeker/hasari-api/apps/desktop/src/components/ProtectedRoute.tsx
-
curl -L -o ProtectedRoute.tsx https://huggingface.co/spaces/erdoganpeker/hasari-api/resolve/main/apps/desktop/src/components/ProtectedRoute.tsx
622 Bytes
| /** | |
| * Route guard — redirects to /login when no auth user is present. | |
| * Renders nothing until the auth context has finished bootstrapping (avoids login-flash). | |
| */ | |
| import { ReactNode } from 'react'; | |
| import { Navigate, useLocation } from 'react-router-dom'; | |
| import { useAuth } from '@/contexts/AuthContext'; | |
| export function ProtectedRoute({ children }: { children: ReactNode }) { | |
| const { user, ready } = useAuth(); | |
| const loc = useLocation(); | |
| if (!ready) return null; | |
| if (!user) return <Navigate to="/login" replace state={{ from: loc.pathname }} />; | |
| return <>{children}</>; | |
| } | |
| export default ProtectedRoute; | |