Files
cats/client/src/components/ProtectedRoute.tsx

24 lines
856 B
TypeScript

import { Navigate } from 'react-router-dom';
import { useAuth } from '@/hooks/useAuth';
import { Cat } from 'lucide-react';
export default function ProtectedRoute({ children }: { children: React.ReactNode }) {
const { user, isLoading } = useAuth();
if (isLoading) {
return (
<div className="flex h-screen items-center justify-center bg-[var(--bg)]">
<div className="flex flex-col items-center gap-5">
<div className="h-14 w-14 rounded-2xl flex items-center justify-center bg-[var(--accent)]">
<Cat className="h-7 w-7 text-white" strokeWidth={1.5} />
</div>
<div className="h-5 w-5 rounded-full border-2 border-[var(--border)] border-t-[var(--accent)] animate-spin" />
</div>
</div>
);
}
if (!user) return <Navigate to="/login" replace />;
return <>{children}</>;
}