SOURCE.IO / src /components /RequireAuth.tsx
Adeen
Deploy: OCR support for PDF/Images/DOCX
ae14296
import { Navigate, useLocation } from "react-router-dom";
import { useAuth } from "@/hooks/useAuth";
import { Loader2 } from "lucide-react";
export default function RequireAuth({ children }: { children: React.ReactNode }) {
const { user, loading } = useAuth();
const location = useLocation();
if (loading) {
return (
<div className="min-h-screen flex items-center justify-center">
<Loader2 className="h-5 w-5 animate-spin text-muted-foreground" />
</div>
);
}
if (!user) return <Navigate to="/auth" state={{ from: location }} replace />;
return <>{children}</>;
}