A Next.js sample project built on top of Kontent.ai. It mirrors the Karma healthcare site and serves as a reference for integrating Kontent.ai into a Next.js application.
- Delivery SDK with strongly-typed content via generated models (
src/utils/client.server.ts,src/model/) - Draft Mode preview — uses Next.js Draft Mode to preview unpublished content. Toggle it through the
/api/preview/enableand/api/preview/disableroutes; while enabled, pages render preview data instead of published content. - Rich text rendering with
@kontent-ai/rich-text-resolver-reactand custom Portable Text resolvers (src/utils/richtext.tsx) - Smart Link in-context editing on the landing page and on detail pages for blog posts, services, research articles, and team members. The SDK is wired inside
*Preview.tsxclient components (src/components/screens/). Index pages intentionally have no Smart Link — editing happens on each item's detail route. - Taxonomy-based filtering on the research listing page (
src/components/research/ArticleListWithFilters.tsx) - App-wide localization with
next-intlunder a[locale]segment; a global language switcher in the header swaps locales while preserving the current route (src/components/LanguageSwitcher.tsx). - Type generation from the Kontent.ai content model (
scripts/generateModel.ts)
- Node.js and npm
- Clone the repo
git clone https://github.com/kontent-ai/karma-nextjs-app.git
- Install dependencies
npm ci
- Create a
.env.localfile from.env.templateand fill in the Kontent.ai and Auth0 values. At minimum you needKONTENT_ENVIRONMENT_ID,KONTENT_DELIVERY_API_KEY,AUTH0_DOMAIN,AUTH0_CLIENT_ID, andSESSION_PASSWORD. The app derives its own public URL from each request, so every origin you serve it from (localhost, production, preview deployments) must be listed in the Auth0 application's Allowed Callback URLs (<origin>/callback) and Allowed Logout URLs (<origin>); Auth0 supports subdomain wildcards for preview deployments. - Run the app
npm run dev
If you only need the single default environment, you can strip the Auth0 layer out:
- Delete the
src/app/[locale]/envid/route tree,src/app/auth/,src/app/callback/,src/lib/auth0/,src/lib/kontentInternalApi/,src/lib/env/resolveApiKey.ts,src/lib/sanitizeReturnTo.ts, andsrc/proxy.ts. - Replace
src/components/EnvLink.tsxwith a plainnext/link, and remove the/envid/prefix handling fromsrc/components/Header.tsxandsrc/components/Navigation.tsx. - Drop the Auth0 variables from
.env.templateand uninstall the now-unusediron-sessionandopenid-clientdependencies.
After updating the content model in Kontent.ai, regenerate the TypeScript models with the Kontent.ai Model Generator:
npm run model:generateNote
Ensure .env.local contains KONTENT_ENVIRONMENT_ID and KONTENT_MANAGEMENT_API_KEY.
Some flows require HTTPS in development — most notably the session cookie, which uses SameSite=None; Secure so it works inside the Kontent.ai preview iframe. Run:
npm run dev:httpsThis starts Next.js with --experimental-https, generating a local certificate so the dev server is served over HTTPS.
For Contributing please see CONTRIBUTING.md for more information.
Distributed under the MIT License. See LICENSE.md for more information.