Integrate Creem payments into Next.js with our official adapter. React components, webhook handlers, and subscription management in minutes. Works with App Router and Pages Router.
@creem_io/nextjs is the official adapter for running Creem inside the Next.js App Router. It gives you:
🎨 React Components — Drop-in checkout and portal components that wrap routing logic.
🔐 Type-safe APIs — Full TypeScript coverage and sensible defaults.
⚡ Zero-config setup — Works with App Router filesystem routing.
🪝 Webhook helpers — Automatic verification and strongly typed handlers.
🔄 Subscription lifecycle — Built-in helpers for grant/revoke access flows.
Use it as your default integration path whenever you are building on Next.js. For other runtimes, you can still call the REST API or the TypeScript SDK directly, but this adapter keeps everything in one place.
// app/checkout/route.tsimport { Checkout } from '@creem_io/nextjs';export const GET = Checkout({ apiKey: process.env.CREEM_API_KEY!, testMode: true, // flip to false in production defaultSuccessUrl: '/thank-you',});
// page.tsx'use client'; // Optional: Works with server side componentsimport { CreemCheckout } from '@creem_io/nextjs';export default function SubscribeButton() { return ( <CreemCheckout productId="prod_abc123" successUrl="/thank-you"> <button className="btn-primary">Subscribe Now</button> </CreemCheckout> );}
// app/api/webhook/creem/route.tsimport { Webhook } from '@creem_io/nextjs';export const POST = Webhook({ webhookSecret: process.env.CREEM_WEBHOOK_SECRET!, onGrantAccess: async ({ customer, metadata }) => { // The user should be granted access const userId = metadata?.referenceId as string; await grantAccess(userId, customer.email); }, onRevokeAccess: async ({ customer, metadata }) => { // The user should have their access revoked const userId = metadata?.referenceId as string; await revokeAccess(userId, customer.email); },});
Once these routes are in place you can test end-to-end by creating a checkout session, redirecting the user, and watching the webhook fire.