Setup
Configure generate-metadata in your Next.js application
Complete setup guide for integrating generate-metadata with your Next.js application.
Prerequisites
- Next.js 13+ with App Router
- generate-metadata installed (
npm install generate-metadata
) - DSN from generate-metadata.com
- API key for authentication (required for Next.js adapter)
Environment Configuration
1. Add Environment Variables
Create or update your .env.local
file:
Use NEXT_PUBLIC_
prefix for client-side access in Next.js applications. The
API key should not use this prefix as it should remain server-side only.
The apiKey
parameter is required for the Next.js adapter. Without it,
TypeScript will throw a compilation error.
2. Create Metadata Client
Create a shared client instance:
Basic Page Setup
App Router Pages
Dynamic Pages
Layout Metadata
Cache Revalidation Setup
The revalidation handler allows you to programmatically clear the metadata cache when your content changes.
Create the revalidation API route handler:
Keep your revalidate secret secure. Never expose it in client-side code or public repositories.
Verification
Check Developer Tools
Open your browser's developer tools and inspect the <head>
section to verify meta tags are being generated.