Add inline content editing to a Next.js site

A Next.js site often starts with copy in code or in a database only developers touch. That works until marketing needs a new headline every week. Inline editing lets them change it on the page, while you decide exactly which fields they may touch.

The usual options, and why they're heavy

When a Next.js team is asked to “let marketing edit the homepage”, the usual answers are:

Inline editing is a fourth option. Your data stays where it is, your auth stays as it is, and editors change content on the rendered page. You write a little glue code; the editing UI, the AI and the endpoints come from a package.

How it fits an App Router app

vibe-editor-next is an adapter for the App Router. It owns the HTTP endpoints, the field allow-list and the calls to Vibe Editor. You supply small callbacks that authenticate the user and read and write a field with your own stack — NextAuth, Clerk, Prisma, Drizzle, Mongoose or anything else.

Requirements are short: the App Router (an app/ directory can live next to pages/), the Node.js runtime with a server, and a developer key from your Vibe Editor account. A static export can't work, because there would be nowhere safe to keep the key.

1. Configure the handlers

Install the package and put the key in your server environment — never with a NEXT_PUBLIC_ prefix:

npm install vibe-editor-next

# .env.local
VIBE_API_KEY=vibe_...

Then one config file says which fields are editable and how to reach them:

// src/vibe/config.ts
import { getServerSession } from 'next-auth'
import { revalidatePath } from 'next/cache'
import { createVibeHandlers } from 'vibe-editor-next'
import { authOptions } from '@/lib/auth'
import { db } from '@/lib/db'

export const vibe = createVibeHandlers({
  allow: [{ collection: 'news', field: 'title' }, { collection: 'news', field: 'body' }],
  getUser: async () => (await getServerSession(authOptions))?.user ?? null,
  isAuthorized: (u) => Boolean((u as any)?.isAdmin),
  read: async ({ collection, id, field }) => db.read(collection, id, field),
  write: async ({ collection, id, field, value }) => db.write(collection, id, field, value),
  onSaved: async () => revalidatePath('/', 'layout'),
})

Only allow, getUser, isAuthorized, read and write are required. Pictures and page titles add a few optional callbacks.

2. Mount the routes

Each endpoint is a one-line route handler under src/app/api/vibe/:

// src/app/api/vibe/suggest/route.ts
import { vibe } from '@/vibe/config'
export const POST = vibe.suggest
export const runtime = 'nodejs'
export const dynamic = 'force-dynamic'

You need suggest, save, asset and status for text. Pictures add swap-image, media and generate-image. The package ships an example folder with every route ready to copy.

3. Load the editor for admins, and mark the content

// src/app/layout.tsx
import { VibeEditor } from 'vibe-editor-next/component'

export default async function RootLayout({ children }) {
  const isAdmin = await currentUserIsAdmin()
  return (
    <html lang="en"><body>
      {children}
      <VibeEditor enabled={isAdmin} apiBase="/api/vibe" mediaBase="/api/vibe/media" />
    </body></html>
  )
}

Then tell the editor which element shows which field with data-vibe-* attributes:

<article data-vibe-collection="news" data-vibe-id={item._id}>
  <h1 data-vibe-field="title">{item.title}</h1>
  <div data-vibe-field="body">{/* rendered markdown */}</div>
</article>

Where the security boundary is

The enabled prop only decides whether the editor loads. The real checks run on the server, on every request:

There's no separate editor login: the editor rides your app's existing session. And the AI never runs in the browser — suggestions go from your server to Vibe Editor with your key, which stays on the server.

Pictures and page titles

For pictures, your app keeps ownership of storage: a callback receives the generated image bytes and returns the id, URL and alt text, and another fills the media library grid. Store generated pictures in object storage or your database rather than public/, which Next.js won't serve for files written at runtime. AI pictures take 10–60 seconds, so on serverless raise maxDuration on the generate-image route.

For SEO, a pageMeta callback tells the adapter where each page's title and description live, and you read them back in generateMetadata. Editors then change both from the magnifier button on the page — see how to write them well.

When this is the right choice

Inline editing suits sites where content already lives in your own database and the people editing it mostly change existing text and pictures. If you need editors to create complex new page structures, model content types or run approval workflows, a headless CMS is the better base — and if you use Payload, you can add on-page editing on top of it.

The full reference, including every route and option, is in the Next.js docs.

Keep reading

Page builders vs headless CMS vs on-page editing: what your editors need

Three ways to let people change a website, what each is good at, and why on-page editing works next to the other two.

3 min read

Payload CMS admin vs on-page editing: when to use which

Keep Payload's admin for structure and new content, and let editors make everyday fixes on the page — through the same access control.

3 min read