Docs · Platforms

Next.js

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 to authenticate, read and write with your own auth and database (NextAuth, Clerk, Prisma, Drizzle, Mongoose — anything).

Requirements

Install

npm install vibe-editor-next
# .env.local — never prefix it with NEXT_PUBLIC_
VIBE_API_KEY=vibe_...

1. Configure (one file)

// 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 add swapImage, listMedia and saveGeneratedImage; page titles add pageMeta.

2. Mount the route handlers

One small file per route 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'
FileExportNeeded for
suggest/route.tsPOST = vibe.suggestRequired: AI rewrites
save/route.tsPOST = vibe.saveRequired: saving text, alt text, titles
asset/[file]/route.tsGET = vibe.assetRequired: serves the overlay
status/route.tsGET = vibe.statusRequired: AI available, credits left
swap-image/route.tsPOST = vibe.swapImagePictures
media/route.tsGET = vibe.mediaThe media library grid
generate-image/route.tsPOST = vibe.generateImageAI pictures

The package's example/ folder has every route ready to copy.

3. Load it in your layout (admins only)

// 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>
  )
}

4. Mark editable content

<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>
  <img data-vibe-field="imageId" data-vibe-alt="imageAlt" src={item.imageUrl} alt={item.imageAlt ?? ''} />
</article>

data-vibe-alt is optional: it names the field that holds the picture's alt text, so editors can change it. Add that field to allow too.

Who can edit

The overlay rides your app's existing session; there is no separate editor login. Three checks run on the server on every request:

CheckFails with
getUser(req) returns null401
isAuthorized(user) returns false403
Field not in allow403

The component's enabled prop only decides whether the overlay loads; the checks above are the security boundary.

Pictures

The Endre bilde panel offers an AI picture (built on the current one when it fits), a pasted image URL, the media library, and alt text. Your app owns storage: saveGeneratedImage gets the PNG bytes and returns { id, url, alt }; listMedia fills the library grid. Store generated pictures in object storage or your database, not in public/ (Next.js won't serve files written there at runtime).

Page title and description

Tell the adapter where each page's title and description are kept with pageMeta, and read them back in generateMetadata with vibe.getPageMeta(path):

// in vibe/config.ts
pageMeta: ({ path }) => ({ collection: 'pageMeta', id: path, title: 'title', description: 'description' }),

// in a page
export async function generateMetadata({ params }) {
  const { slug } = await params
  const saved = await vibe.getPageMeta(`/news/${slug}`)
  return { title: saved.title ? { absolute: saved.title } : 'News', description: saved.description }
}

Deployment notes

Credits

AI calls are paid from the Vibe Editor account the developer key belongs to. Every new account starts with 20 free credits; plans and top-ups are on the pricing section.

ActionCredits
AI text suggestion1
AI picture5
AI suggestion for a page title or meta description1 each
Saving text you typed, a picture from the library or by URL, alt text, a title or descriptionFree

When the credits run out, the editor says so and links to where you can buy more. If the AI fails, the credits are given back.

The editor's buttons are in Norwegian today. The ones you'll meet most: Endre tekst (edit text), Skriv selv (type it yourself), Endre bilde (change picture), Flere valg (more options), Alt-tekst (alt text), Side i søkemotorer (page in search engines), Foreslå med AI (suggest with AI), Lagre (save) and Koble til Vibe Editor (connect).

Read more on the blog