Spaces:
Runtime error
Runtime error
Download frontend/src/components/layout/ProtectedRoute.tsx from SII-gelingli/echem-agent: direct link, hf CLI and curl.
- Browser
- Download file 739 Bytes
-
https://huggingface.co/spaces/SII-gelingli/echem-agent/resolve/main/frontend/src/components/layout/ProtectedRoute.tsx
- Command line
-
hf download hf://spaces/SII-gelingli/echem-agent/frontend/src/components/layout/ProtectedRoute.tsx
-
curl -L -o ProtectedRoute.tsx https://huggingface.co/spaces/SII-gelingli/echem-agent/resolve/main/frontend/src/components/layout/ProtectedRoute.tsx
739 Bytes
| import { useEffect } from 'react'; | |
| import { Navigate } from 'react-router-dom'; | |
| import { Spin } from 'antd'; | |
| import { useAuthStore } from '../../stores/authStore'; | |
| export default function ProtectedRoute({ children }: { children: React.ReactNode }) { | |
| const { isAuthenticated, loading, loadUser, user } = useAuthStore(); | |
| useEffect(() => { | |
| if (isAuthenticated && !user) { | |
| loadUser(); | |
| } | |
| }, [isAuthenticated, user, loadUser]); | |
| if (!isAuthenticated) { | |
| return <Navigate to="/login" replace />; | |
| } | |
| if (loading) { | |
| return ( | |
| <div style={{ display: 'flex', justifyContent: 'center', alignItems: 'center', height: '100vh' }}> | |
| <Spin size="large" /> | |
| </div> | |
| ); | |
| } | |
| return <>{children}</>; | |
| } | |