"use client"; import { useEffect, ReactNode } from "react"; import { useRouter } from "next/navigation"; import { useAuth } from "@/components/auth/auth-provider"; function FullScreenLoader() { return (
); } export function RouteGuard({ children }: { children: ReactNode }) { const { isAuthenticated, isLoading } = useAuth(); const router = useRouter(); useEffect(() => { if (!isLoading && !isAuthenticated) { const next = encodeURIComponent(window.location.pathname); router.replace(`/login?next=${next}`); } }, [isLoading, isAuthenticated, router]); if (isLoading) return ; if (!isAuthenticated) return ; return <>{children}; }