Backend
    September 15, 2026•7 min read

    Embedding Payload CMS inside your Next.js app

    Running the CMS in the same app as the site means no API round trips and one deploy. A look at reading data through the local API and keeping static pages fresh.

    Anonymous
    Embedding Payload CMS inside your Next.js app

    Payload 3 installs into a Next.js app instead of running beside it. The admin panel is a route, and your server components can query the database directly through the local API.

    Reading data without HTTP

    TYPESCRIPT
    1import { getPayload } from 'payload'
    2import config from '@payload-config'
    3
    4export async function getLatestPosts() {
    5  const payload = await getPayload({ config })
    6
    7  const { docs } = await payload.find({
    8    collection: 'blog-posts',
    9    where: { _status: { equals: 'published' } },
    10    sort: '-publishDate',
    11    limit: 3,
    12  })
    13
    14  return docs
    15}

    If a collection has drafts enabled, always filter on _status. The local API skips access control by default, so it will happily return unpublished content.

    Keeping static pages fresh

    Statically rendered pages need a nudge when content changes. An afterChange hook that calls revalidatePath does it:

    TYPESCRIPT
    1import type { CollectionAfterChangeHook } from 'payload'
    2import { revalidatePath } from 'next/cache'
    3
    4export const revalidateHome: CollectionAfterChangeHook = ({ doc, req: { context } }) => {
    5  if (!context.disableRevalidate) {
    6    revalidatePath('/')
    7  }
    8
    9  return doc
    10}

    Scripts that run outside Next.js, like a seed, pass context: { disableRevalidate: true }. Give every call its own object: Payload uses it as req.context as-is, and plugins store per-request state on it.

    #Payload CMS
    #Next.js
    #TypeScript
    Share: