Next.js Auth & Stripe Starter agent skill
Build a protected Next.js App Router dashboard with Supabase Auth, Stripe-hosted Checkout, and verified subscription webhooks. It gives developers using Cursor or Claude Code a repeatable build sequence and sandbox checks for access, retries, and billing state.
Profile reviewed by the Vibe Coding Editorial Team · Updated 2026-11-30
Installation
Install the skill in Claude Code or Cursor
Use this Claude Code skill template as a project skill or save it in Cursor’s skill directory. Match the folder name to the YAML name field.
- Claude Code
.claude/skills/nextjs-auth-stripe-starter/SKILL.md - Cursor
.cursor/skills/nextjs-auth-stripe-starter/SKILL.md
Invoke /nextjs-auth-stripe-starter in your agent or paste the prompt below to start a one-off build. If you already keep Cursor rules for Next.js, use .cursor/rules/*.mdc for persistent conventions such as server-only imports. Use this skill for the full billing workflow.
Vibe Coding’s Claude Code skills guideClaude Code skill formatCursor skillsCursor project rules
Requires a TypeScript Next.js App Router project, Supabase Auth and Postgres, and a Stripe sandbox.
Best for
- Adding a subscription plan to an existing Next.js app
- Reviewing server-side auth and Stripe webhook handling
What it adds
- Provides a complete project skill and a one-off starter prompt.
- Defines server-side access checks, webhook verification, and sandbox acceptance tests.
- 01Inspect the repo and preserve its auth and billing conventions.
- 02Add the server-side auth guard, Checkout route, and webhook updates.
- 03Run sandbox tests for ownership, retries, and subscription access.
Skills are instructions with consequences
- Use a local or staging database and keep Stripe sandbox and live resources separate.
- Keep privileged keys server-side and verify webhook signatures before applying any state change.
- Check database migrations and rollback steps before applying them to a shared environment.
Prerequisites and stack boundaries
- Use a TypeScript Next.js App Router project, a compatible Node.js runtime, and the package manager from its lockfile.
- Set up Supabase Auth and Postgres on a local or staging database. Use a publishable key for user sessions and a separate server-only client for webhook writes.
- Create one recurring price in a Stripe sandbox. This starter covers one user per billing account and grants access for the configured price with an active subscription. Team billing, trials, and live billing migrations need their own design.
- Verify user ownership and the plan on the server. Keep secrets out of the browser. Verify webhook signatures before writing, and commit event deduplication and billing state in the same transaction.
Next.js authentication guideSupabase server-side AuthStripe subscription Checkout
Required environment variables
Commit these names with placeholders in .env.example. Set real values in your untracked local environment or hosting secret store.
- NEXT_PUBLIC_SUPABASE_URL
- Project URL for the development or staging Supabase project.
- NEXT_PUBLIC_SUPABASE_PUBLISHABLE_KEY
- Supabase publishable key for session-aware access governed by row-level security.
- SUPABASE_SECRET_KEY
- Server-only key for the webhook database client. It bypasses row-level security and must stay out of user-facing routes.
- STRIPE_SECRET_KEY
- Server-only Stripe sandbox API key for local development.
- STRIPE_WEBHOOK_SECRET
- Server-only signing secret for the particular CLI listener or deployed webhook destination.
- STRIPE_PRICE_ID
- Server-owned recurring price ID from the same Stripe environment as the API key.
- APP_URL
- Trusted origin for Checkout redirects, such as http://localhost:3000 for local development.
SKILL.md
---
name: nextjs-auth-stripe-starter
description: Add or review Supabase Auth, protected routes, Stripe subscription Checkout, and verified webhooks in a Next.js App Router project. Use for a single-price SaaS starter and its sandbox verification.
---
# Next.js Auth & Stripe Starter
## When to use
Use this skill when asked to add sign-in, protect a dashboard or API, start Stripe Checkout, sync subscription state, or verify one of those flows in a Next.js App Router repo. Read the repository instructions, lockfile, and existing auth and billing code first. Reuse established conventions and propose a scoped adaptation if the project uses another provider or a different account model.
## Scope and prerequisites
- Use Next.js App Router with TypeScript, a compatible Node.js runtime, Supabase Auth with @supabase/ssr, Supabase Postgres, and the Stripe Node SDK.
- Assume one verified user per billing account, one recurring Stripe Price, and Stripe-hosted Checkout. This starter grants access only for the configured price with status active. Trials, team billing, migrations of live accounts, and production deployment are outside this task.
- Work in a development branch with a local or staging database and Stripe sandbox. Keep test and live credentials, products, prices, and endpoints separate. Obtain approval before applying a migration to a shared database, changing live Stripe resources, or deploying.
- Add variable names to .env.example with blank or descriptive placeholder values. Configure values through local environment files or the host's secret store. Only the Supabase URL and publishable key are public here. Keep the Stripe keys, webhook secret, and privileged Supabase key in server-only modules. Never print or paste secrets into chat, logs, or fixtures.
Required environment variables
- NEXT_PUBLIC_SUPABASE_URL — Project URL for the development or staging Supabase project.
- NEXT_PUBLIC_SUPABASE_PUBLISHABLE_KEY — Supabase publishable key for session-aware access governed by row-level security.
- SUPABASE_SECRET_KEY — Server-only key for the webhook database client. It bypasses row-level security and must stay out of user-facing routes.
- STRIPE_SECRET_KEY — Server-only Stripe sandbox API key for local development.
- STRIPE_WEBHOOK_SECRET — Server-only signing secret for the particular CLI listener or deployed webhook destination.
- STRIPE_PRICE_ID — Server-owned recurring price ID from the same Stripe environment as the API key.
- APP_URL — Trusted origin for Checkout redirects, such as http://localhost:3000 for local development.
## File conventions
- app/(protected)/dashboard/page.tsx — server-rendered account and billing view. Use src/app when the repo already uses src/.
- app/api/stripe/checkout/route.ts — authenticated POST that creates or resumes Checkout.
- app/api/stripe/webhook/route.ts — Node.js POST that authenticates Stripe with the signature.
- lib/supabase/ and lib/billing/ — session helpers, server-only clients, price configuration, and entitlement checks. Keep the privileged webhook client separate from the user client.
- supabase/migrations/ — billing tables, ownership policies, unique constraints, and an atomic write function. Use the repo's existing migration directory if it differs.
- tests/ — use the repo's test layout for auth, Checkout, webhook, and entitlement coverage.
## Implementation order
1. Inspect and plan. Identify the app root, package manager, installed versions, auth guard, and test scripts. List the files and schema changes before editing. Keep working sign-in and billing flows in place.
2. Verify identity on the server. Use cookie-aware Supabase SSR and the project's supported session refresh mechanism. Verify identity with getClaims() or getUser() as appropriate. Guard every protected page, Route Handler, and Server Action at the data or mutation boundary. Scope reads to the verified user. Enable row-level security for user-facing billing reads and deny user writes to entitlement and webhook tables.
3. Create Checkout on the server. Require the signed-in user for POST and enforce the app's same-origin or CSRF protection. Read the recurring price from trusted server configuration. Derive customer ownership from the verified user and stored Stripe customer mapping. Save that mapping before creating a Session. Use mode subscription and build redirects from APP_URL. Serialize Checkout attempts per account, reuse a valid open Session, and block another purchase while a subscription already exists and can be recovered. Persist an attempt identifier and use a stable Stripe idempotency key for retries of that attempt.
4. Verify the webhook before handling it. Read the original body once with await request.text() and pass it with Stripe-Signature and the endpoint's signing secret to stripe.webhooks.constructEvent. Return 400 on a missing or invalid signature with no database write. Accept only the expected Stripe mode and handle the configured subscription lifecycle events. Use checkout.session.completed for reconciliation where needed. Keep this endpoint reachable without a browser login.
5. Persist billing state safely. Resolve the Stripe customer to a server-owned user mapping. Acknowledge supported events after their effects are durably committed. In one database transaction, claim the unique event ID and apply the subscription projection. On a failed write, roll back the event claim and return a retryable response. Treat already committed events as successful no-ops. Restrict any privileged database function to the backend role used for webhooks. Webhooks can arrive out of order. Reconcile against current Stripe subscription state, and serialize the read-and-write per account or use a database revision check with a fresh Stripe read after any conflict. An event for a previous subscription must never replace a newer subscription on the same account.
6. Enforce entitlements in the application. Open paid routes and actions only after server-side ownership, subscription status, and price checks. The Checkout success URL can show pending confirmation while the webhook catches up. Query parameters, client state, and the redirect itself never grant access. Handle cancellation and payment failure according to the stored subscription status.
## Verification
Use the package manager from the lockfile. Example commands for a pnpm repo with those scripts, using separate terminals for the app and listener.
pnpm run dev
stripe listen --events checkout.session.completed,customer.subscription.created,customer.subscription.updated,customer.subscription.deleted --forward-to http://localhost:3000/api/stripe/webhook
pnpm run lint
pnpm exec tsc --noEmit
pnpm run test
pnpm run build
If a script is absent, use the repo's equivalent and report any checks you could not run. Set the local webhook secret from the listener output in your untracked environment and restart the app if required. Sign in with a test user and complete hosted Checkout with sandbox payment details. Confirm the stored status before checking access.
- Verify signed-out rejection and isolation between two test accounts.
- Verify that a client-supplied price cannot alter the server-approved plan and that repeat Checkout attempts do not create extra subscriptions.
- Test a valid signed delivery, a bad signature, and repeat delivery of the same event ID. Verify that a failed write can retry and an out-of-order delivery cannot regress state.
- Test that visiting the success URL before webhook processing leaves access unchanged, then confirm access changes after valid state is persisted. Verify cancellation or another ineligible status removes access.
Report changed files, migration and rollback steps, required variable names, commands run, and any sandbox or deployment checks still pending. Do not claim end-to-end success without observed evidence.
Master Prompt for vibe coding tools
Paste this into an agent session opened at your repo root. For other tasks, browse the vibe coding prompts library.
Work in the current Next.js App Router repository. Add a signed-in dashboard and one recurring plan using Supabase Auth, Supabase Postgres, and Stripe-hosted Checkout in sandbox mode. Reuse the existing auth, data, routing, and testing conventions. If the repo uses a different provider or account model, explain the adaptation before changing it.
First inspect the lockfile, package scripts, auth helpers, and billing schema. Give me a short file-level plan and state the assumed billing account model.
Then implement a server-side auth and ownership check on every protected data read or mutation. Build a Checkout POST that uses a server-configured price, trusted redirect URLs, a verified customer mapping, and retry-safe Checkout creation. Build a Node.js webhook POST that verifies Stripe-Signature against the untouched request body before any write. Commit event deduplication and the billing-state update together. Reconcile against current Stripe state so retries and out-of-order deliveries cannot overwrite newer billing state.
Grant paid access only from verified server-side entitlement state. Treat the success redirect as pending until the stored subscription qualifies. Keep privileged keys server-only. Put variable names and placeholders in .env.example and leave real credentials out of code, logs, and this conversation.
Use the repo's lint, type-check, test, and build commands. Cover signed-out requests, account isolation, untrusted prices, invalid signatures, repeated events, and cancellation. Exercise sandbox Checkout and webhook delivery when credentials are configured. Summarize changed files, migration and rollback steps, checks you actually ran, and anything still pending. Ask before applying a shared database migration, touching live billing, or deploying.
Common auth and Stripe failures
- Webhook signature verification fails
- Pass the unchanged body and Stripe-Signature header to Stripe’s verifier. Locally, use the secret printed by the active Stripe CLI listener. On staging or production, use the secret for the exact webhook destination and confirm its mode and URL.
- A webhook retry changes billing twice
- Put a unique constraint on the event ID and commit the event record and subscription update together. Test the retry after a forced database failure. Read current Stripe state when a delayed event arrives.
- A signed-out user reaches protected data
- Verify the session and ownership at each protected server query, Route Handler, and Server Action. Test direct requests while signed out and while signed in to another account.
- Checkout succeeds but paid access stays locked
- Check the Stripe delivery log, mapped customer, stored subscription status, and recurring price. Show a pending state until the verified update is committed.
- A double-click opens two Checkout Sessions
- Store one open Checkout attempt per account, reuse its Session, and keep the same Stripe idempotency key when retrying the attempt. Check for an existing subscription before creating a new Session.
Stripe signature troubleshootingStripe webhook delivery and retriesProduction launch checklist
Next.js Auth & Stripe Starter FAQ
Questions before installation
Check fit, compatibility, prerequisites, permissions, and source ownership before adding this skill to a coding agent.
What does the Next.js Auth & Stripe Starter agent skill do?
Build a protected Next.js App Router dashboard with Supabase Auth, Stripe-hosted Checkout, and verified subscription webhooks. Its main capabilities include provides a complete project skill and a one-off starter prompt; defines server-side access checks, webhook verification, and sandbox acceptance tests.
When should I use nextjs-auth-stripe-starter?
Use it for adding a subscription plan to an existing next.js app, reviewing server-side auth and stripe webhook handling. A skill is most useful when this is a recurring workflow and its instructions improve results compared with a normal one-off prompt.
Which coding agents are compatible with nextjs-auth-stripe-starter?
The current profile lists Claude Code, Cursor. Skill support changes quickly, so confirm the latest installation directory, discovery behavior, and tool permissions in your agent’s documentation before installing.
What do I need before installing this skill?
You need a TypeScript Next.js App Router project, Supabase Auth and Postgres, and a Stripe sandbox. Copy SKILL.md into the project skills directory for your agent, or paste the Master Prompt into an agent session.
Can this skill run commands or change files?
A skill supplies instructions and resources to an agent. Whether it can run commands, edit files, browse, or call external services depends on the tools and permissions available to that agent. Review requested actions at runtime and keep sensitive operations approval-gated.
Is this skill maintained by Vibe Coding?
Vibe Coding publishes this starter. The complete SKILL.md, Master Prompt, and references are available on this page.
Customize this workflow for your repo
Use the Skill Generator to define your own provider, account model, and verification steps. Use the Prompt Generator for a single build or review.
Related skills
Engineering
Supabase Postgres Best Practices
Review Postgres schemas, queries, and migrations using Supabase guidance on performance and data access.
Open skillEngineering
React Best Practices
Apply prioritized React and Next.js performance guidance from Vercel Engineering while writing or reviewing code.
Open skillEngineering
MCP Builder
Guide the design and implementation of Model Context Protocol servers with useful, well-scoped tools.
Open skill