This is a Next.js project bootstrapped with create-next-app.
- Node.js 18+ installed
- Clerk account with billing enabled
- Stripe account connected to Clerk (for billing)
-
Copy
.env.exampleto.env:cp .env.example .env
-
Get your Clerk API keys from Clerk Dashboard and add them to
.env:NEXT_PUBLIC_CLERK_PUBLISHABLE_KEYCLERK_SECRET_KEYCLERK_WEBHOOK_SECRET(optional, for webhooks)
-
Set up Prisma Postgres database:
- Create a Prisma Postgres database via Prisma MCP or use a local PostgreSQL instance
- Get the connection string and add it to
.envasDATABASE_URL - Run
npm run prisma:migrateto create the database schema - Run
npm run prisma:generateto generate Prisma Client
-
Configure billing in Clerk Dashboard:
- Enable billing feature
- Connect your Stripe account
- Create subscription plans and features
- Configure webhook endpoint:
https://your-domain.com/api/webhooks/clerk(for production)
npm installnpm run dev
# or
yarn dev
# or
pnpm dev
# or
bun devOpen http://localhost:3000 with your browser to see the result.
This project uses @fontsource/jetbrains-mono to load JetBrains Mono, a monospace font designed for developers.
This project uses Prisma ORM with PostgreSQL to store user and billing data:
- Schema: Defined in
prisma/schema.prismawith User, Subscription, and BillingHistory models - Migrations: Run
npm run prisma:migrateto apply schema changes - Prisma Studio: Run
npm run prisma:studioto view and edit database data - Webhooks: Clerk webhooks automatically sync user and subscription data to the database
- User: Stores user information synced from Clerk
- Subscription: Tracks user subscription plans and status
- BillingHistory: Records payment history and invoices
This project uses Clerk Billing for subscription management:
- Pricing Page:
/pricing- Displays subscription plans using Clerk's<PricingTable />component - Account Page:
/account- User profile and subscription management using Clerk's<UserProfile />component - Protected Content: Use
<Protect>component orhas()method to restrict access based on subscription plans - API Routes:
/api/user- Get current user data and subscription/api/user/subscription- Get user's active subscription/api/user/billing-history- Get user's payment history
Server Components:
import { auth } from '@clerk/nextjs/server';
export default async function Page() {
const { has } = await auth();
const hasPremiumPlan = has({ plan: 'premium' });
if (!hasPremiumPlan) {
return <div>Premium content only</div>;
}
return <div>Premium content here</div>;
}Client Components:
"use client";
import { Protect } from "@clerk/nextjs";
export default function Page() {
return (
<Protect plan="premium" fallback={<div>Premium content only</div>}>
<div>Premium content here</div>
</Protect>
);
}To learn more about Next.js, take a look at the following resources:
- Next.js Documentation - learn about Next.js features and API.
- Learn Next.js - an interactive Next.js tutorial.
You can check out the Next.js GitHub repository - your feedback and contributions are welcome!
The easiest way to deploy your Next.js app is to use the Vercel Platform from the creators of Next.js.
Check out our Next.js deployment documentation for more details.