• Stars
    star
    6,499
  • Rank 6,101 (Top 0.2 %)
  • Language
    TypeScript
  • License
    MIT License
  • Created about 4 years ago
  • Updated 3 months 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
126,710
star
2

hyper

A terminal built on web technologies
TypeScript
43,324
star
3

swr

React Hooks for Data Fetching
TypeScript
30,461
star
4

turborepo

Build system optimized for JavaScript and TypeScript, written in Rust
Rust
25,810
star
5

pkg

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

vercel

Develop. Preview. Ship.
TypeScript
12,555
star
7

commerce

Next.js Commerce
TypeScript
11,287
star
8

satori

Enlightened library to convert HTML and CSS to SVG
TypeScript
11,019
star
9

micro

Asynchronous HTTP microservices
TypeScript
10,525
star
10

ai

Build AI-powered applications with React, Svelte, Vue, and Solid
TypeScript
9,836
star
11

serve

Static file serving and directory listing
TypeScript
9,208
star
12

ncc

Compile a Node.js project into a single file. Supports TypeScript, binary addons, dynamic requires.
JavaScript
9,063
star
13

styled-jsx

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

ai-chatbot

A full-featured, hackable Next.js AI chatbot built by Vercel
TypeScript
6,579
star
15

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,650
star
16

ms

Tiny millisecond conversion utility
TypeScript
4,912
star
17

og-image

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

next-learn

Learn Next.js Starter Code
TypeScript
3,710
star
19

release

Generate changelogs with a single command
JavaScript
3,558
star
20

examples

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

hazel

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

next-plugins

Official Next.js plugins
2,677
star
23

next-app-router-playground

https://app-router.vercel.app/
TypeScript
2,534
star
24

geist-font

2,250
star
25

virtual-event-starter-kit

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

async-retry

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

react-tweet

Embed tweets in your React application.
TypeScript
1,615
star
28

little-date

A friendly formatter to make date ranges small & sweet
TypeScript
1,553
star
29

nft

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

arg

Simple argument parsing
JavaScript
1,222
star
31

style-guide

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

avatar

💎 Beautiful avatars as a microservice
TypeScript
1,155
star
33

nextjs-postgres-nextauth-tailwindcss-template

Admin dashboard template.
TypeScript
1,108
star
34

modelfusion

The TypeScript library for building AI applications.
TypeScript
1,084
star
35

next-react-server-components

Demo repository for Next.js + React Server Components
JavaScript
985
star
36

nextjs-postgres-auth-starter

Next.js + Tailwind + Typescript + Drizzle + NextAuth + PostgreSQL starter template.
TypeScript
915
star
37

nextgram

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

edge-runtime

Developing, testing, and defining the runtime Web APIs for Edge infrastructure.
TypeScript
790
star
39

on-demand-isr

TypeScript
762
star
40

server-components-notes-demo

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

micro-dev

The development environment for `micro`
JavaScript
705
star
42

nextjs-portfolio-starter

Easily create a portfolio with Next.js and Markdown.
JavaScript
669
star
43

async-sema

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

static-fun

A fun demo for wildcard domains
TypeScript
629
star
45

hyperpower

Hyper particle effects extension
JavaScript
623
star
46

react-keyframes

Create frame-based animations in React
TypeScript
617
star
47

title

A service for capitalizing your title properly
JavaScript
579
star
48

fetch

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

serve-handler

The foundation of `serve`
JavaScript
564
star
50

vrs

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

storage

Vercel Postgres, KV, Blob, and Edge Config
TypeScript
506
star
52

fun

ƒun - Local serverless function λ development runtime
TypeScript
480
star
53

swr-site

The official website for SWR.
MDX
479
star
54

mongodb-starter

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

hyper-site

The official website for the Hyper terminal
JavaScript
435
star
56

spr-landing

Serverless Pre-Rendering Landing Page
CSS
434
star
57

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
428
star
58

analytics

Privacy-friendly, real-time traffic insights
TypeScript
421
star
59

sveltekit-commerce

SvelteKit Commerce
Svelte
386
star
60

reactions

Next.js Incremental Static Regeneration Demo
JavaScript
309
star
61

email-prompt

CLI email prompt with autocompletion and built-in validation
JavaScript
274
star
62

uid-promise

Creates a cryptographically strong UID
TypeScript
252
star
63

fetch-retry

Wrapper around `fetch` with sensible retrying defaults
JavaScript
221
star
64

git-hooks

No nonsense Git hook management
JavaScript
202
star
65

zsh-theme

Yet another zsh theme
179
star
66

remote-cache

The Vercel Remote Cache SDK
TypeScript
174
star
67

cosmosdb-server

A Cosmos DB server implementation for testing your applications locally.
TypeScript
170
star
68

react-transition-progress

Show a progress bar while React Transitions run
TypeScript
162
star
69

update-check

Minimalistic update notifications for command line interfaces
JavaScript
159
star
70

test-listen

Quick ephemeral URLs for your tests
JavaScript
153
star
71

terraform-provider-vercel

Terraform Vercel Provider
Go
142
star
72

install-node

Simple one-liner shell script that installs official Node.js binaries
Shell
141
star
73

title-site

A website for capitalizing your titles
JavaScript
126
star
74

community

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

preview-mode-demo

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

nextjs-discord-bot

Discord bot for the official Next.js Discord
TypeScript
108
star
77

beginner-sveltekit

The complete course to start your journey building Svelte applications.
JavaScript
101
star
78

commerce-framework

TypeScript
99
star
79

err-sh

Microservice that forwards you to error messages
JavaScript
97
star
80

webpack-asset-relocator-loader

Used in ncc while emitting and relocating any asset references
JavaScript
96
star
81

hyperyellow

Example theme for hyperterm
JavaScript
87
star
82

schemas

All schemas used for validation that are shared between our projects
JavaScript
80
star
83

opentelemetry-collector-dev-setup

Shell
72
star
84

nuxt3-kitchen-sink

An example template showing all Nuxt 3 features on Vercel.
Vue
67
star
85

next-codemod

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

speed-insights

Vercel Speed Insights package
TypeScript
56
star
87

ai-sdk-rag-starter

TypeScript
55
star
88

wait-for

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

async-listen

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

tracing-js

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

example-integration

TypeScript
42
star
92

dns-cached-resolve

Caching DNS resolver
TypeScript
41
star
93

fetch-cached-dns

A decorator on top of `fetch` that caches the DNS query
JavaScript
36
star
94

resolve-node

API endpoint to resolve an arbitrary Node.js version with semver support
JavaScript
30
star
95

remark-capitalize

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

cra-to-next

An example of migrating Create React App to Next.js.
JavaScript
29
star
97

otel

OTEL tracing for Vercel
TypeScript
27
star
98

stripe-integration

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

rcurl

`curl --resolve` helper script
Shell
23
star
100

gatsby-plugin-vercel

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