Spaces:
Runtime error

echem-agent / frontend /src /components /layout /ProtectedRoute.tsx
SII-gelingli
Initial deployment to HF Spaces
ccab613
Raw History Blame Contribute Delete
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}</>;
}