Next.js SaaS template for products that need billing state synced from Commet into their own database. It uses Commet webhooks as the source of truth for customer access, subscription status, payments, usage, and local event history.
Stack: Next.js 16, Better Auth, Drizzle ORM, PostgreSQL, Commet SDK
Quick Start
git clone https://github.com/commet-labs/commet.git
cd commet/examples/webhooks
pnpm install
pnpm devWhat's Included
Two public plans with monthly and yearly prices
Three metered features: API Calls, Storage, Email Sends
Checkout and subscription activation flow
Signed webhook endpoint for Commet events
Idempotent event recording before critical handlers run
Customer state sync from
customer.state_changedUsage updates from
usage.recordedLocal webhook feed for inspecting delivered events
Dashboard showing plan, status, renewal, and feature access
Key Files
app/api/webhooks/commet/route.ts— Signed webhook endpoint with event logging and idempotencylib/billing/sync.ts— Customer state snapshot synclib/billing/usage.ts— Usage event persistencelib/webhooks/events.ts— Local webhook event recordingapp/(dashboard)/dashboard/events/page.tsx— Webhook feedapp/(dashboard)/dashboard/page.tsx— Billing state overviewapp/pricing/page.tsx— Dynamic pricing from Commet plans
Production Setup
Add
COMMET_API_KEYfrom your Commet sandbox or live organizationAdd
COMMET_WEBHOOK_SECRETfrom the Commet webhook endpointSet
NEXT_PUBLIC_APP_URLto your deployed app URLRegister
/api/webhooks/commetas a Commet webhook endpointSubscribe the endpoint to customer, subscription, payment, invoice, checkout, and usage events
Learn More
Clone the repo to start, check the live demo, or browse the source on GitHub.
