Local Development using Supabase
Develop locally
If you haven't already done so, clone your Github repository to your local machine.
Configure Auth
Follow this guide to set up an OAuth app with GitHub and configure Supabase to use it as an auth provider.
In your Supabase project, navigate to auth > URL configuration and set your main production URL (e.g. https://your-deployment-url.vercel.app) as the site url.
Next, in your Vercel deployment settings, add a new Production environment variable called NEXT_PUBLIC_SITE_URL
and set it to the same URL. Make sure to deselect preview and development environments to make sure that preview branches and local development work correctly.
Install dependencies
Ensure you have pnpm installed and run:
Local Development with Supabase
Prerequisites
Install Docker: Download and install Docker from here.
Setup Environment Files: Copy or rename .env.local.example
to
.env.local
. Copy or rename .env.example
to .env
.
Starting Local Supabase Instance
Start Supabase: Open your terminal. Run the following command to start a local Supabase instance and set up the database schema:
Note the URLs provided in the terminal output for accessing different services within the Supabase stack.
Configure Environment Variables: Copy the value of service_role_key
from the terminal output. Open your .env.local
file. Set
SUPABASE_SERVICE_ROLE_KEY
in your .env.local
file with the copied value.
Print Supabase URLs: Open your terminal. Run the following command to print out the URLs:
This will print the
following keys that we will use in our environment variables. Copy these
values and paste them in your .env.local
file:
Link Local Supabase Instance to Project: Open your terminal. Run the following command:
Navigate to the Supabase project you created. Enter your database password when prompted.
Database Password Reset
Reset Database Password: Visit your database settings. Click "Reset database password". Copy the new password and store it in a password manager.
Schema Changes and Data Seeding
Pull Schema Changes: Open your terminal. Run the following command to pull schema changes from your remote database:
Seed Local Database: Open your terminal. Run the following commands to generate seed data:
Generating Types and Migrations
Generate TypeScript Types: Open your terminal. Run the following command to generate TypeScript types to match your schema:
Generate Migration File: Open your terminal. Run the following command to automatically generate a migration file with all the changes you've made to your local database schema:
Push those changes to your remote database with:
Use the Stripe CLI to Test Webhooks
Setting Up Stripe CLI
Login to Stripe Account: Use the Stripe CLI to login to your Stripe account:
This will print a URL to navigate to in your browser and provide access to your Stripe account.
Start Local Webhook Forwarding: Run the following command:
This will print a webhook secret (such as whsec_***
) to
the console. Set STRIPE_WEBHOOK_SECRET
to this value in your .env.local
file. If you haven't already, set NEXT_PUBLIC_STRIPE_PUBLISHABLE_KEY
and
STRIPE_SECRET_KEY
in your .env.local
file using the test mode keys
from your Stripe dashboard.
Final environment variables
By now your environment variables should look like this:
Run the Next.js Client
Start Development Server: Open a separate terminal. Run the following command to start the development server:
Note that webhook forwarding and the development server must be running concurrently in two separate terminals for the application to work correctly.
View Application: Navigate to http://localhost:3000 in your browser to see the application rendered.