Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 | import { Navigate, useLocation } from 'react-router-dom'; import { useAuth } from '@/contexts/AuthContext'; export default function ProtectedRoute({ children }: { children: React.ReactNode }) { const { token, isLoading } = useAuth(); const location = useLocation(); if (isLoading) { return ( <div className="auth-page"> <div className="spinner spinner-themed" /> </div> ); } if (!token) { return <Navigate to="/" state={{ from: location.pathname }} replace />; } return <>{children}</>; } |