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
- The App Router (an
app/directory can live next topages/). - The Node.js runtime and a server. Static export (
output: 'export') can't work: there is nowhere to keep the key. - A developer key from your account page.
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'
| File | Export | Needed for |
|---|---|---|
suggest/route.ts | POST = vibe.suggest | Required: AI rewrites |
save/route.ts | POST = vibe.save | Required: saving text, alt text, titles |
asset/[file]/route.ts | GET = vibe.asset | Required: serves the overlay |
status/route.ts | GET = vibe.status | Required: AI available, credits left |
swap-image/route.ts | POST = vibe.swapImage | Pictures |
media/route.ts | GET = vibe.media | The media library grid |
generate-image/route.ts | POST = vibe.generateImage | AI 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:
| Check | Fails with |
|---|---|
getUser(req) returns null | 401 |
isAuthorized(user) returns false | 403 |
Field not in allow | 403 |
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
- basePath: prefix
apiBase, e.g.<VibeEditor apiBase="/blog/api/vibe" />. - next/image: add the host of pasted or generated pictures to
images.remotePatterns, or serve them from your own origin. - Timeouts: an AI picture takes 10–60 seconds. On serverless set
export const maxDuration = 150ongenerate-image; behind nginx raiseproxy_read_timeout. - Docker / standalone: works as is; the overlay is built into the package, so nothing needs copying.
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.
| Action | Credits |
|---|---|
| AI text suggestion | 1 |
| AI picture | 5 |
| AI suggestion for a page title or meta description | 1 each |
| Saving text you typed, a picture from the library or by URL, alt text, a title or description | Free |
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).
Try now