"use client";

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

// Watches the client-side session state and redirects to /auth/signin
// when the session expires mid-SPA-session (without a full page reload).
// Rendered in the authenticated layout — never visible to the user.
export function SessionGuard() {
  const { status } = useSession();
  const router = useRouter();

  useEffect(() => {
    if (status === "unauthenticated") {
      router.replace("/auth/signin");
    }
  }, [status, router]);

  return null;
}
