import { useEffect, useState } from 'react'; import type { ReactNode } from 'react'; import { Navigate, useLocation } from 'react-router-dom'; import { Spin } from 'antd'; import { authApi } from '../services/api'; interface ProtectedRouteProps { children: ReactNode; } export default function ProtectedRoute({ children }: ProtectedRouteProps) { const [isAuthenticated, setIsAuthenticated] = useState(null); const location = useLocation(); useEffect(() => { const checkAuth = async () => { try { await authApi.getCurrentUser(); setIsAuthenticated(true); } catch { setIsAuthenticated(false); } }; checkAuth(); }, []); if (isAuthenticated === null) { return (
); } if (!isAuthenticated) { return ; } return <>{children}; }