import { headers } from "next/headers"; import { getPayload } from "payload"; import config from "@payload-config"; import type { Customer } from "@/payload-types"; /** Returns the logged-in customer for the current request, or null. Never returns an admin user. */ export async function getCurrentCustomer(): Promise { const payload = await getPayload({ config }); const { user } = await payload.auth({ headers: await headers() }); if (!user || user.collection !== "customers") return null; return user as Customer; }