• Stars
    star
    5,334
  • Rank 7,355 (Top 0.2 %)
  • Language
    TypeScript
  • License
    MIT License
  • Created over 3 years ago
  • Updated 13 days ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Clone, deploy, and fully customize a SaaS subscription application with Next.js.

Next.js Subscription Payments Starter

The all-in-one starter kit for high-performance SaaS applications.

Features

Demo

Screenshot of demo

Architecture

Architecture diagram

Step-by-step setup

When deploying this template, the sequence of steps is important. Follow the steps below in order to get up and running.

The process is slightly different depending upon whether you start from Github or you start from Vercel, but it should work either way.

Note: We're working on our Stripe integration. We've documented the required steps below under "Configure Stripe" until the integration is ready.

Initiate Deployment

Initiate Vercel Deployment

To get started from Github, click the "Deploy" button below. You may do this either from your own fork or from the original template repo.

Vercel will prompt you to create a new Github repo. If you've used a fork, you may link your Vercel deployment to your existing fork by selecting "Import a different Git repository" from the left menu. If you've used the master template or started from the Vercel website instead of Github, you may allow Vercel to create a repo for you.

Open a Codespace or clone the repo

Before proceeding with your Vercel deployment, you'll need to set up a Supabase project. For this step, it will be helpful to either open a Github codespace from your fork or clone the repo to your local machine. To clone the repo, use git clone https://github.com/[your_username]/[your_repo_name] and then cd [your_repo_name].

Set up Supabase

Create a Supabase project

On Supabase, create a Supabase account and create a project, with any name you like. Also generate an access token from https://app.supabase.com/account/tokens. You will need this later.

Run schema.sql

From your Github fork, copy the code from schema.sql. In your Supabase project, navigate to the SQL editor, click New Query, paste the code, and run the code. This will create the necessary tables and RLS policies in your Supabase database.

Set up redirect wildcards for deploy previews

For auth redirects (magic links, OAuth providers) to work correctly in deploy previews, navigate to the auth settings (i.e. https://app.supabase.com/project/:project-id/auth/url-configuration) and add the following wildcard URL to "Redirect URLs": https://**vercel.app/*/*. (You can read more about redirect wildcard patterns in the docs.)

[Optional] - Set up OAuth providers

You can use third-party login providers like GitHub or Google. Refer to the docs to learn how to configure these. Once configured, you can add them to the provider array of the Auth component on the signin.tsx page.

Generate types from your Supabase database

Now open a terminal in your codespace or cloned repo. You can use the Supabase CLI to generate types from your Database by running:

  1. To install Supabase cli
npm install supabase --save-dev
yarn add supabase --dev
  1. Connect to Supabase
npx supabase login
  1. Enter the access token you created earlier. (As mentioned above, you can generate an access token from https://app.supabase.com/account/tokens.)

  2. Generate types

npx supabase gen types typescript --project-id [YOUR-PROJECT-REF] --schema public > types_db.ts

Set up Supabase environment variables

Next, we need to set up environment variables for our Supabase project. We can copy these from Supabase > Project Settings > API and paste them into the Vercel deployment interface. Copy project API keys and paste into the NEXT_PUBLIC_SUPABASE_ANON_KEY and SUPABASE_SERVICE_ROLE_KEY fields, and copy the project URL and paste to Vercel as NEXT_PUBLIC_SUPABASE_URL.

This completes Supabase setup.

Configure Stripe

Next, we'll need to configure Stripe to handle test payments. If you don't already have a Stripe account, create one now.

For the following steps, make sure you have the "Test Mode" toggle switched on.

Create a webhook

We need to create a webhook in the Developers section of Stripe. Pictured in the architecture diagram above, this webhook is the piece that connects Stripe to your Vercel Serverless Functions.

  1. Click the "Add Endpoint" button on the test Endpoints page.
  2. Enter any placeholder text for the endpoint URL. (We will return later and change this to https://your-deployment-url.vercel.app/api/webhooks once we complete deployment to Vercel.)
  3. Click Select events under the Select events to listen to heading.
  4. Click Select all events in the Select events to send section.
  5. Copy Signing secret as we'll need that in the next step.

Set Stripe environment variables

To securely interact with Stripe, we need to add a few more Environment Variables in the Vercel deployment interface.

  • NEXT_PUBLIC_STRIPE_PUBLISHABLE_KEY
  • STRIPE_SECRET_KEY
  • STRIPE_WEBHOOK_SECRET_LIVE

You can find the first two keys on the API keys tab in Stripe. The STRIPE_WEBHOOK_SECRET_LIVE is the Signing secret copied in the previous webhook configuration step.

Complete deployment

Complete Vercel deployment

Once you've set your environment variables in the Vercel deployment interface, complete your deployment. Vercel may take a few minutes to build your application. It will then provide you with a domain URL for your deployment. Copy this URL and add it to .env.local:

NEXT_PUBLIC_SITE_URL=https://your-deployment-url.vercel.app

Keep the url on your clipboard, because you will also need it for the next step.

NOTE: Vercel assigns you a domain that is stable from deployment to redeployment (https://your-deployment-url.vercel.app) and a dynamic URL that changes every time you redploy (e.g., https://your-deployment-url.vercel-12345678-your-organization.app). You want to use the stable one, not the dynamic one!

Complete Stripe webhook configuration

Now that we have a deployment URL, we can complete our Stripe webhook configuration. Go back to the Stripe test Webhooks page. Click your endpoint, and then click ... > Update Details. In the Endpoint URL field, paste your deployment URL and add /api/webhooks to the end. For example, if your deployment URL is https://your-deployment-url.vercel.app, then your endpoint URL should be https://your-deployment-url.vercel.app/api/webhooks. Click Update endpoint.

Create product and pricing information

Your application's webhook listens for product updates on Stripe and automatically propagates them to your Supabase database. So with your webhook listener running, you can now create your product and pricing information in the Stripe Dashboard.

Stripe Checkout currently supports pricing that bills a predefined amount at a specific interval. More complex plans (e.g., different pricing tiers or seats) are not yet supported.

For example, you can create business models with different pricing tiers, e.g.:

  • Product 1: Hobby
    • Price 1: 10 USD per month
    • Price 2: 100 USD per year
  • Product 2: Freelancer
    • Price 1: 20 USD per month
    • Price 2: 200 USD per year

Optionally, to speed up the setup, we have added a fixtures file to bootstrap test product and pricing data in your Stripe account. The Stripe CLI fixtures command executes a series of API requests defined in this JSON file. Simply run stripe fixtures fixtures/stripe-fixtures.json.

Important: Be sure webhook forwarding is active when you create your products, or the products created will not be imported into your database.

Configure the Stripe customer portal

  1. Set your custom branding in the settings
  2. Configure the Customer Portal settings
  3. Toggle on "Allow customers to update their payment methods"
  4. Toggle on "Allow customers to update subscriptions"
  5. Toggle on "Allow customers to cancel subscriptions"
  6. Add the products and prices that you want
  7. Set up the required business information and links

That's it

That's it. Now you're ready to earn recurring revenue from your customers. πŸ₯³

Develop locally

If you haven't already done so, clone your Github repository to your local machine.

Next, use the Vercel CLI to link your project:

vercel login
vercel link

Setting up the env vars locally

Use the Vercel CLI to download the development env vars:

vercel env pull .env.local

Running this command will create a new .env.local file in your project folder. For security purposes, you will need to set the SUPABASE_SERVICE_ROLE_KEY manually from your Supabase dashboard (Settings > API).

Use the Stripe CLI to test webhooks

Install the Stripe CLI and link your Stripe account.

Next, start local webhook forwarding:

stripe listen --forward-to=localhost:3000/api/webhooks

Running this Stripe command will print a webhook secret (such as, whsec_***) to the console. Set STRIPE_WEBHOOK_SECRET to this value in your .env.local file.

Install dependencies and run the Next.js client

In a separate terminal, run the following commands to install dependencies and start the development server:

npm install
npm run dev
# or
yarn
yarn dev

Note that webhook forwarding and the development server must be running concurrently in two separate terminals for the application to work correctly.

Finally, navigate to http://localhost:3000 in your browser to see the application rendered.

Going live

Archive testing products

Archive all test mode Stripe products before going live. Before creating your live mode products, make sure to follow the steps below to set up your live mode env vars and webhooks.

Configure production environment variables

To run the project in live mode and process payments with Stripe, switch Stripe from "test mode" to "production mode." Your Stripe API keys will be different in production mode, and you will have to create a separate production mode webhook. Copy these values and paste them into Vercel, replacing the test mode values.

Redeploy

Afterward, you will need to rebuild your production deployment for the changes to take effect. Within your project Dashboard, navigate to the "Deployments" tab, select the most recent deployment, click the overflow menu button (next to the "Visit" button) and select "Redeploy."

To verify you are running in production mode, test checking out with the Stripe test card. The test card should not work.

A note on reliability

This template mirrors completed Stripe transactions to the Supabase database. This means that if the Supabase database is unavailable, the Stripe transaction will still succeed, but the Supabase database will not be updated, and the application will pass an error code back to Stripe. By default, Stripe will retry sending its response to the webhook for up to three days, or until the database update succeeds. This means that the Stripe transaction will eventually be reflected in the Supabase database as long as the database comes back online within three days. You may want to implement a process to automatically reconcile the Supabase database with Stripe in case of a prolonged outage.

More Repositories

1

next.js

The React Framework
JavaScript
120,483
star
2

hyper

A terminal built on web technologies
TypeScript
42,467
star
3

swr

React Hooks for Data Fetching
TypeScript
29,423
star
4

turbo

Incremental bundler and build system optimized for JavaScriptΒ and TypeScript, written in Rust – including Turbopack and Turborepo.
Rust
24,396
star
5

pkg

Package your Node.js project into an executable
JavaScript
24,151
star
6

vercel

Develop. Preview. Ship.
TypeScript
11,950
star
7

micro

Asynchronous HTTP microservices
TypeScript
10,525
star
8

commerce

Next.js Commerce
TypeScript
10,203
star
9

satori

Enlightened library to convert HTML and CSS to SVG
TypeScript
10,131
star
10

serve

Static file serving and directory listing
TypeScript
9,088
star
11

ncc

Compile a Node.js project into a single file. Supports TypeScript, binary addons, dynamic requires.
JavaScript
8,786
star
12

ai

Build AI-powered applications with React, Svelte, Vue, and Solid
TypeScript
7,728
star
13

styled-jsx

Full CSS support for JSX without compromises
JavaScript
7,577
star
14

platforms

A full-stack Next.js app with multi-tenancy and custom domain support. Built with Next.js App Router and the Vercel Domains API.
TypeScript
5,193
star
15

ms

Tiny millisecond conversion utility
TypeScript
4,912
star
16

ai-chatbot

A full-featured, hackable Next.js AI chatbot built by Vercel
TypeScript
4,894
star
17

og-image

Open Graph Image as a Service - generate cards for Twitter, Facebook, Slack, etc
TypeScript
4,031
star
18

release

Generate changelogs with a single command
JavaScript
3,544
star
19

examples

Enjoy our curated collection of examples and solutions. Use these patterns to build your own robust and scalable applications.
TypeScript
3,288
star
20

next-learn

Learn Next.js Starter Code
TypeScript
3,181
star
21

hazel

Lightweight update server for Electron apps
JavaScript
2,855
star
22

next-plugins

Official Next.js plugins
2,676
star
23

app-playground

https://app-dir.vercel.app/
TypeScript
2,260
star
24

virtual-event-starter-kit

Open source demo that Next.js developers can clone, deploy, and fully customize for events.
TypeScript
2,115
star
25

geist-font

1,846
star
26

async-retry

Retrying made simple, easy and async
JavaScript
1,780
star
27

arg

Simple argument parsing
JavaScript
1,191
star
28

react-tweet

Embed tweets in your React application.
TypeScript
1,188
star
29

nft

Node.js dependency tracing utility
JavaScript
1,182
star
30

avatar

πŸ’Ž Beautiful avatars as a microservice
TypeScript
1,065
star
31

style-guide

Vercel's engineering style guide
JavaScript
1,064
star
32

next-react-server-components

Demo repository for Next.js + React Server Components
JavaScript
962
star
33

nextjs-postgres-auth-starter

Next.js + Tailwind + Typescript + Drizzle + NextAuth + PostgreSQL starter template.
TypeScript
817
star
34

nextjs-postgres-nextauth-tailwindcss-template

Admin dashboard template.
TypeScript
797
star
35

edge-runtime

Developing, testing, and defining the runtime Web APIs for Edge infrastructure.
TypeScript
736
star
36

server-components-notes-demo

Experimental demo of React Server Components with Next.js. Deployed serverlessly on Vercel.
TypeScript
723
star
37

micro-dev

The development environment for `micro`
JavaScript
695
star
38

nextgram

A sample Next.js app showing dynamic routing with modals as a route.
TypeScript
681
star
39

nextjs-portfolio-starter

Easily create a portfolio with Next.js and Markdown.
JavaScript
635
star
40

react-keyframes

Create frame-based animations in React
TypeScript
615
star
41

hyperpower

Hyper particle effects extension
JavaScript
613
star
42

static-fun

A fun demo for wildcard domains
TypeScript
610
star
43

async-sema

Semaphore using `async` and `await`
TypeScript
602
star
44

title

A service for capitalizing your title properly
JavaScript
576
star
45

fetch

Opinionated `fetch` (with retrying and DNS caching) optimized for use with Node.js
JavaScript
564
star
46

serve-handler

The foundation of `serve`
JavaScript
545
star
47

vrs

A serverless virtual reality e-commerce experience powered by Vercel
TypeScript
517
star
48

swr-site

The official website for SWR.
MDX
464
star
49

fun

Ζ’un - Local serverless function Ξ» development runtime
TypeScript
462
star
50

storage

Vercel Postgres, KV, Blob, and Edge Config
TypeScript
455
star
51

mongodb-starter

A developer directory built on Next.js and MongoDB Atlas, deployed on Vercel with the Vercel + MongoDB integration.
TypeScript
439
star
52

spr-landing

Serverless Pre-Rendering Landing Page
CSS
426
star
53

hyper-site

The official website for the Hyper terminal
JavaScript
418
star
54

pkg-fetch

A utility to fetch or build patched Node binaries used by `pkg` to generate executables. This repo hosts prebuilt binaries in Releases.
TypeScript
412
star
55

analytics

Privacy-friendly, real-time traffic insights
TypeScript
384
star
56

sveltekit-commerce

SvelteKit Commerce
Svelte
357
star
57

reactions

Next.js Incremental Static Regeneration Demo
JavaScript
308
star
58

email-prompt

CLI email prompt with autocompletion and built-in validation
JavaScript
275
star
59

uid-promise

Creates a cryptographically strong UID
TypeScript
250
star
60

fetch-retry

Wrapper around `fetch` with sensible retrying defaults
JavaScript
220
star
61

git-hooks

No nonsense Git hook management
JavaScript
198
star
62

zsh-theme

Yet another zsh theme
178
star
63

remote-cache

The Vercel Remote Cache SDK
TypeScript
169
star
64

cosmosdb-server

A Cosmos DB server implementation for testing your applications locally.
TypeScript
167
star
65

update-check

Minimalistic update notifications for command line interfaces
JavaScript
157
star
66

test-listen

Quick ephemeral URLs for your tests
JavaScript
153
star
67

install-node

Simple one-liner shell script that installs official Node.js binaries
Shell
136
star
68

terraform-provider-vercel

Terraform Vercel Provider
Go
129
star
69

title-site

A website for capitalizing your titles
JavaScript
123
star
70

preview-mode-demo

This demo showcases Next.js' next-gen Static Site Generation (SSG) support.
TypeScript
105
star
71

nextjs-discord-bot

Discord bot for the official Next.js Discord
TypeScript
100
star
72

beginner-sveltekit

The complete course to start your journey building Svelte applications.
JavaScript
97
star
73

err-sh

Microservice that forwards you to error messages
JavaScript
96
star
74

community

Welcome to the Vercel Community. Discuss feature requests, ask questions, and connect with others in the community.
96
star
75

webpack-asset-relocator-loader

Used in ncc while emitting and relocating any asset references
JavaScript
95
star
76

commerce-framework

TypeScript
94
star
77

hyperyellow

Example theme for hyperterm
JavaScript
87
star
78

schemas

All schemas used for validation that are shared between our projects
JavaScript
78
star
79

nuxt3-kitchen-sink

An example template showing all Nuxt 3 features on Vercel.
Vue
64
star
80

next-codemod

codemod transformations to help upgrade Next.js codebases
JavaScript
63
star
81

react-transition-progress

Show a progress bar while React Transitions run
TypeScript
57
star
82

otel

TypeScript
54
star
83

opentelemetry-collector-dev-setup

Shell
50
star
84

async-listen

Promisify server.listen for your HTTP/HTTPS/TCP server.
TypeScript
45
star
85

wait-for

Small utility that waits for a file to exist and optionally have some permissions set.
C
44
star
86

tracing-js

An implementation of Opentracing API for honeycomb.io
TypeScript
43
star
87

dns-cached-resolve

Caching DNS resolver
TypeScript
40
star
88

example-integration

TypeScript
38
star
89

fetch-cached-dns

A decorator on top of `fetch` that caches the DNS query
JavaScript
35
star
90

speed-insights

Vercel Speed Insights package
TypeScript
30
star
91

remark-capitalize

Transform all markdown titles with title.sh
JavaScript
29
star
92

resolve-node

API endpoint to resolve an arbitrary Node.js version with semver support
JavaScript
29
star
93

cra-to-next

An example of migrating Create React App to Next.js.
JavaScript
24
star
94

ng-deploy-vercel

Deploy Angular applications to Vercel
TypeScript
22
star
95

stripe-integration

A Vercel deploy integration to automatically set up your Stripe API keys and webhook secrets.
TypeScript
21
star
96

rcurl

`curl --resolve` helper script
Shell
21
star
97

release-auth

Handles the authentication for `release`
JavaScript
21
star
98

gatsby-plugin-vercel

Track Core Web Vitals in Gatsby projects with Vercel Analytics.
JavaScript
20
star
99

cert-demo

TypeScript
19
star
100

go-bridge

Bridge for `@vercel/go`
Go
18
star