"use client";

import { useSession } from "next-auth/react";
import { usePathname, useRouter } from "next/navigation";
import { useEffect } from "react";

export function AuthCheck({ children }: { children: React.ReactNode }) {
  const { data: session, status } = useSession();
  const pathname = usePathname();
  const router = useRouter();

  useEffect(() => {
    if (status === "unauthenticated" && pathname !== "/signin") {
      router.push("/signin");
    }
  }, [status, router, pathname]);

  if (status === "loading") {
    return <div>Chargement...</div>;
  }

  if (status === "unauthenticated" && pathname !== "/signin") {
    return null;
  }

  return <>{children}</>;
} 