import { getServerSession } from "next-auth";
import { authOptions } from "@/lib/auth/auth-options";

/** Get the current server-side session with role and workspaceId claims. */
export async function getSession() {
  return getServerSession(authOptions);
}

/** Require an authenticated session or throw. */
export async function requireSession() {
  const session = await getSession();
  if (!session?.user?.id) {
    throw new Error("Unauthorized");
  }
  return session;
}
