import { cookies } from "next/headers";
import {
  ADMIN_SESSION_COOKIE,
  verifyAdminSessionToken,
} from "@/lib/auth";

export async function requireAdminApi() {
  const token = (await cookies()).get(ADMIN_SESSION_COOKIE)?.value;
  if (!token || !(await verifyAdminSessionToken(token))) {
    return Response.json({ error: "Unauthorized" }, { status: 401 });
  }
  return null;
}
