Vextalflow Logo
Documentation

Next.js SaaS Starter Template

A comprehensive guide to using and customizing this SaaS starter template to build your own subscription-based web application.

1.1 Installation Process

This section describes the complete process for locally running the application, including Supabase and Stripe integration.

Prerequisites:

  • Installed Node.js and npm
  • Installed Supabase CLI (npm install -g supabase)
  • Accounts created on Supabase, Vercel (optional), and Stripe
  • Project cloned from GitHub repository

1.1.1 Supabase Initialization

For proper connection of the application to the remote (production) Supabase project, several steps need to be performed through the Supabase CLI.

Login to Supabase CLI

First, you need to authenticate in the Supabase CLI using the command:

npx supabase login

When executed, you will be prompted to enter an access token, which can be obtained in your user account at supabase.com/account/tokens.

Link to Project

After successful login, you need to link the local project with a specific Supabase project. This is done by entering the unique project identifier, the so-called project reference, which is part of the URL of the given Supabase project.

npx supabase link --project-ref your-project-ref
Apply Migrations

After linking, all existing migrations are deployed to the database using the command:

npx supabase db push

This step ensures that the database structure in the remote environment corresponds to the design defined in the project.

Note: Before applying migrations, it is recommended to check their content to avoid unwanted changes in the production database.

1.1.2 Environment Setup

Create a .env file in the root directory of the project and add the following variables:

NEXT_PUBLIC_SUPABASE_URL=<SUPABASE_URL>
NEXT_PUBLIC_SUPABASE_ANON_KEY=<SUPABASE_ANON_KEY>
SUPABASE_SERVICE_ROLE_KEY=<SERVICE_ROLE_KEY>
NEXT_PUBLIC_STRIPE_PUBLISHABLE_KEY=<PUBLISHABLE_KEY>
STRIPE_SECRET_KEY=<SECRET_KEY>
STRIPE_WEBHOOK_SECRET=<WEBHOOK_SECRET>
NEXT_PUBLIC_BASE_URL=<http://localhost:3000>

1.1.3 Install Dependencies

After successfully connecting to the backend services and setting up the configuration variables, you need to install all the necessary dependencies for the frontend part of the application. This is done with the following command in the terminal:

npm install

Start the application in development mode with the command:

npm run dev

This will start the local server and the application will be available at:

http://localhost:3000

This mode allows continuous testing and debugging of the application during development.

1.1.4 Stripe (Optional)

Stripe integration is not necessary for basic startup, but it is recommended for full application functionality. Stripe keys need to be inserted into the .env file - these keys are available on the Stripe website.

Authentication Setup

This template uses Supabase for authentication. To configure authentication:

  1. Sign up for a Supabase account at supabase.com
  2. Create a new project and get your API keys
  3. Enable Email and Password sign-in in the Authentication settings
  4. Set up the email templates for verification and password reset
  5. Configure OAuth providers (Google, GitHub, etc.) if needed

Stripe Integration

To set up Stripe for subscription payments:

  1. Create a Stripe account at stripe.com
  2. Create products and price plans in your Stripe dashboard
  3. Copy your API keys and add them to your .env.local file
  4. Set up Stripe webhooks to notify your application of subscription events