"use client";

import { LoadingPage } from "@/components/loading-page";
import { usePrivy } from "@privy-io/react-auth";
import { useRouter } from "next/navigation";

export function CheckSessionProvider({
  children,
}: Readonly<{
  children: React.ReactNode;
}>) {
  const { ready, authenticated } = usePrivy();
  const router = useRouter();

  if (!ready) return <LoadingPage />;

  if (ready && !authenticated) router.replace("/");

  if (ready && authenticated) return children;
}
