Skip to content

ShenSeanChen/launch-mvp-stripe-nextjs-supabase

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

36 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

Next.js + Stripe + Supabase Production-Ready Template

A production-ready Next.js template featuring authentication, dark mode support, Stripe integration, automated email workflows with Resend, and a clean, modern UI. Built with TypeScript and Tailwind CSS.

License Next.js TypeScript Tailwind

πŸ“Ή Full YouTube Guide: Youtube link

πŸš€ X Post: X link

πŸ’‘ Try the App: App link

β˜•οΈ Buy me a coffee: Cafe Latte

πŸ€–οΈ Discord: Invite link

✨ Features

  • πŸ” Authentication with Supabase
  • πŸ’³ Stripe payment integration
  • πŸ“§ Automated Email Workflows with Resend (welcome, billing, cancellation emails)
  • πŸŒ“ Dark mode support
  • πŸ“± Responsive design
  • 🎨 Tailwind CSS styling
  • πŸ”„ Framer Motion animations
  • πŸ›‘οΈ TypeScript support
  • πŸ“Š Error boundary implementation
  • πŸ” SEO optimized
  • πŸ€– MCP integration for AI-powered development

πŸš€ Getting Started

Prerequisites

  • Node.js 18+
  • npm or yarn
  • A Supabase account
  • A Stripe account
  • A Resend account (for emails)
  • A Google Cloud Platform account

Installation and Setup

  1. Clone the template:

Option A: Use GitHub's Template Feature (Easiest)

  • Click the green "Use this template" button on GitHub
  • This creates a fresh repo with clean history

Option B: Clone and Start Fresh (Recommended for production)

git clone https://github.com/ShenSeanChen/launch-mvp-stripe-nextjs-supabase my-full-stack-app
cd my-full-stack-app
rm -rf .git              # Remove template's git history
git init                 # Start fresh with your own history
git add .
git commit -m "Initial commit from LaunchMVP template"
git remote add origin https://github.com/YOUR_USERNAME/my-full-stack-app.git
git push -u origin main

Option C: Fork (For contributors or to receive updates)

  • Click "Fork" on GitHub to maintain connection to this template
  1. Install dependencies:
npm install

or

yarn install
  1. Create .env.local with all variables from .env.example
NEXT_PUBLIC_APP_URL=http://localhost:8000
NEXT_PUBLIC_API_URL=http://localhost:8080
NEXT_PUBLIC_WS_URL=ws://localhost:8080

# Supabase Configuration
# Note: In Supabase Dashboard, these are now called "Publishable key" and "Secret key"
# but the variable names below still work correctly
NEXT_PUBLIC_SUPABASE_URL=
NEXT_PUBLIC_SUPABASE_ANON_KEY=
SUPABASE_SERVICE_ROLE_KEY=

# OpenAI Configuration (you'll need to add your key)
OPENAI_API_KEY=

# Stripe Configuration
# ⚠️ Use TEST keys (pk_test_, sk_test_) during development!
NEXT_PUBLIC_STRIPE_PUBLISHABLE_KEY=pk_test_
NEXT_PUBLIC_STRIPE_BUTTON_ID=buy_btn_
STRIPE_SECRET_KEY=sk_test_
STRIPE_WEBHOOK_SECRET=whsec_

# Email Configuration (Resend)
RESEND_API_KEY=re_xxxxxxxxxxxx
INTERNAL_API_KEY=your_internal_api_key

# ANALYTICS
NEXT_PUBLIC_POSTHOG_KEY=
NEXT_PUBLIC_POSTHOG_HOST=https://app.posthog.com
  1. Set up Google Cloud Platform (GCP):

    • Create new OAuth 2.0 credentials in GCP Console
    • Configure authorized JavaScript origins
    • Configure redirect URIs
    • Save the Client ID and Client Secret
  2. Configure Supabase:

    a. Get API Keys (Project Settings > API):

    • Project URL β†’ NEXT_PUBLIC_SUPABASE_URL
    • Publishable Key (or Anon Key in legacy tab) β†’ NEXT_PUBLIC_SUPABASE_ANON_KEY
    • Secret Key (or Service Role in legacy tab) β†’ SUPABASE_SERVICE_ROLE_KEY

    b. Set up Authentication:

    • Go to Authentication > Providers > Google
    • Add your GCP Client ID and Client Secret
    • Update Site URL and Redirect URLs

    c. Database Setup:

    • Enable Row Level Security (RLS) for all tables
    • Create policies for authenticated users and service roles
    • Create the following trigger function:
    CREATE OR REPLACE FUNCTION public.handle_new_user()
    RETURNS trigger AS $$
    BEGIN
      INSERT INTO public.users (id, email, created_at, updated_at, is_deleted)
      VALUES (NEW.id, NEW.email, NOW(), NOW(), FALSE);
      
      INSERT INTO public.user_preferences (user_id, has_completed_onboarding)
      VALUES (NEW.id, FALSE);
      
      INSERT INTO public.user_trials (user_id, trial_start_time, trial_end_time)
      VALUES (NEW.id, NOW(), NOW() + INTERVAL '48 hours');
      
      RETURN NEW;
    END;
    $$ LANGUAGE plpgsql SECURITY DEFINER;
    
    CREATE TRIGGER on_auth_user_created
      AFTER INSERT ON auth.users
      FOR EACH ROW EXECUTE FUNCTION public.handle_new_user();
  3. Set up Stripe:

    a. Use TEST mode during development:

    • Go to Stripe Dashboard and ensure "Test mode" is enabled (toggle in top-right)
    • Use test card number: 4242 4242 4242 4242
    • Create product in Product Catalog
    • Create promotional coupon codes
    • Set up Payment Link with trial period

    b. Get required keys (from TEST mode):

    • Publishable Key (pk_test_xxx) β†’ NEXT_PUBLIC_STRIPE_PUBLISHABLE_KEY
    • Secret Key (sk_test_xxx) β†’ STRIPE_SECRET_KEY
    • Buy Button ID β†’ NEXT_PUBLIC_STRIPE_BUTTON_ID

    c. Configure webhooks:

    • Add endpoint: your_url/api/stripe/webhook
    • Subscribe to events: customer.subscription., checkout.session., invoice., payment_intent.
    • Copy Signing Secret β†’ STRIPE_WEBHOOK_SECRET
  4. Start the development server:

npm run dev

or

yarn dev
  1. Open http://localhost:3000 in your browser.

πŸ“§ Email Automation Setup

This template includes automated transactional emails using Supabase Database Triggers, Supabase Edge Functions, and Resend. When a user signs up, subscribes, or cancels, they automatically receive beautiful emails.

πŸ“Ή Video Tutorial: Follow along with the YouTube video for a step-by-step walkthrough of this section.

Understanding the Architecture

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚                        WHERE THINGS RUN                                     β”‚
β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
β”‚                                                                              β”‚
β”‚  VERCEL (Next.js App)              SUPABASE (Database + Functions)          β”‚
β”‚  ─────────────────────            ────────────────────────────────          β”‚
β”‚  β€’ Your website UI                 β€’ Database (PostgreSQL)                  β”‚
β”‚  β€’ API routes (/api/*)             β€’ Database Triggers (pg_net)             β”‚
β”‚  β€’ Email service                   β€’ Edge Functions (Deno runtime)          β”‚
β”‚                                                                              β”‚
β”‚  Uses: .env.local or               Uses: supabase secrets                   β”‚
β”‚        Vercel Environment Variables       (separate from Vercel!)           β”‚
β”‚                                                                              β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

Why supabase secrets? Edge Functions run on Supabase's infrastructure (not Vercel), so they need their own environment variables set via supabase secrets set. This is different from the .env.local / Vercel env vars used by your Next.js app.


Step 1: Set up Resend (Email Provider)

  1. Create account at resend.com
  2. Verify your domain at resend.com/domains
    • Add DNS records to your domain
    • For this tutorial: seanchen.io is verified, using [email protected]
  3. Get API key from resend.com/api-keys
  4. Add to your .env.local:
    RESEND_API_KEY=re_xxxxxxxxxxxx
    INTERNAL_API_KEY=generate_a_random_secret_here
    
  5. Also add these to Vercel β†’ Project Settings β†’ Environment Variables

βœ… Verification: Go to Resend dashboard β†’ API Keys. You should see your key listed.


Step 2: Enable pg_net Extension in Supabase

Database triggers need the pg_net extension to make HTTP calls to Edge Functions.

  1. Go to Supabase Dashboard β†’ SQL Editor
  2. Run this SQL:
    CREATE EXTENSION IF NOT EXISTS pg_net WITH SCHEMA extensions;

βœ… Verification: Go to Database β†’ Extensions β†’ Search "pg_net" β†’ Should show "Enabled"


Step 3: Create Email Tracking Table

This table prevents duplicate emails and tracks email history.

  1. Go to Supabase Dashboard β†’ SQL Editor
  2. Run the contents of supabase/scripts/setup/02-create-user-email-log-table.sql

βœ… Verification: Go to Table Editor β†’ You should see user_email_log table


Step 4: Deploy Edge Functions

Edge Functions process the trigger and call your email API.

# Install Supabase CLI
npm install -g supabase

# Login (opens browser for authentication)
supabase login

# Link to your project
# Find your project ref at: Supabase Dashboard β†’ Project Settings β†’ General β†’ Reference ID
supabase link --project-ref YOUR_PROJECT_REF

# Set secrets for Edge Functions (these are DIFFERENT from Vercel env vars!)
supabase secrets set APP_URL=https://my-full-stack-app-iota.vercel.app
supabase secrets set RESEND_API_KEY=re_your_actual_key
supabase secrets set INTERNAL_API_KEY=your_internal_key

# Deploy the functions
supabase functions deploy send-welcome-email
supabase functions deploy send-billing-email
supabase functions deploy send-cancellation-email

βœ… Verification:

  • Go to Supabase Dashboard β†’ Edge Functions
  • You should see all 3 functions listed with "Active" status
  • Click on a function β†’ Check "Logs" tab for any errors

Step 5: Create Database Triggers

Triggers watch for database changes and call the Edge Functions.

  1. Go to Supabase Dashboard β†’ SQL Editor
  2. IMPORTANT: Open supabase/scripts/setup/03-create-public-users-trigger.sql and replace:
    • YOUR_SUPABASE_PROJECT_REF β†’ Your project reference
    • YOUR_SUPABASE_ANON_KEY β†’ Your anon key (find at Project Settings β†’ API)
  3. Run the modified SQL
  4. Repeat for supabase/scripts/setup/04-create-billing-cancellation-triggers.sql

βœ… Verification:

  • The SQL output should show "βœ… Trigger Created Successfully!"
  • Go to Database β†’ Triggers β†’ You should see the triggers listed

Step 6: Test the Flow! πŸŽ‰

  1. Go to your app (e.g., http://localhost:3000)
  2. Sign up with a new account
  3. Check your email inbox for the Welcome email!

βœ… Verification if something goes wrong:

  • Supabase β†’ Edge Functions β†’ Click function β†’ Logs (see if trigger called it)
  • Vercel β†’ Deployments β†’ Functions β†’ Check /api/email/send logs
  • Resend β†’ Emails (see if email was sent)

Preview Email Templates

Visit http://localhost:3000/preview-email to preview your email templates locally before deploying.


Email Architecture Diagram

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚                        EMAIL AUTOMATION FLOW                                 β”‚
β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
β”‚                                                                              β”‚
β”‚  User Signs Up β†’ Supabase Auth β†’ public.users INSERT                        β”‚
β”‚                                        ↓                                     β”‚
β”‚                               Database Trigger                               β”‚
β”‚                                        ↓                                     β”‚
β”‚                               Edge Function                                  β”‚
β”‚                                        ↓                                     β”‚
β”‚                              /api/email/send                                 β”‚
β”‚                                        ↓                                     β”‚
β”‚                                 Resend API                                   β”‚
β”‚                                        ↓                                     β”‚
β”‚                               πŸ“§ Email Delivered                             β”‚
β”‚                                                                              β”‚
β”‚  Similarly for Billing & Cancellation emails via subscriptions table        β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
Email Type Trigger Description
Welcome User signs up Sent when public.users receives an INSERT
Billing Confirmation Subscription created Sent when subscriptions receives an INSERT
Cancellation Subscription cancelled Sent when subscriptions is updated with cancelled status

πŸ› οΈ MCP Integration Setup

What is MCP?

MCP (Model Control Protocol) enables enhanced AI assistant capabilities for this project, allowing the AI to interact directly with your Stripe and Supabase accounts to help with debugging, configuring, and managing your application.

For a comprehensive demonstration of MCP capabilities, check out our dedicated demo repository:

Setting up MCP

  1. Create an mcp.json file:

    Copy the example file to create your own configuration:

    cp .cursor/mcp.json.example .cursor/mcp.json
  2. Configure your credentials:

    a. Stripe Integration:

    • Get your Stripe API key from the Stripe Dashboard
    • Replace your_stripe_test_key_here with your actual test key

    b. Supabase Integration:

    • Generate a Supabase access token from your Supabase dashboard (Project Settings > API)
    • Replace your_supabase_access_token_here with your actual token

    c. GitHub Integration (optional):

    • Create a GitHub Personal Access Token with appropriate permissions
    • Replace your_github_personal_access_token_here with your actual token
  3. Example of a completed mcp.json file:

    {
      "mcpServers": {
        "stripe": {
          "command": "npx",
          "args": [
            "-y", 
            "@stripe/mcp"
          ],
          "env": {
            "STRIPE_SECRET_KEY": "sk_test_51ABC123..."
          }
        },
        "supabase": {
          "command": "npx",
          "args": [
            "-y",
            "@supabase/mcp-server-supabase@latest",
            "--access-token",
            "sbp_1234abcd5678efgh..."
          ]
        }
      }
    }
  4. Using MCP with AI assistants:

    After configuring mcp.json, the AI assistant within the Cursor editor will be able to:

    • Query and manage your Stripe subscriptions
    • Interact with your Supabase database
    • Help troubleshoot integration issues
    • Provide contextual help based on your actual configuration
  5. Security Considerations:

    • Never commit your mcp.json file to version control
    • Use test credentials during development
    • Limit access tokens to only the permissions needed

Extending MCP with Additional Tools

The MCP framework can be extended with various tools beyond Stripe and Supabase. Our launch-mcp-demo repository demonstrates how to integrate basic MCP examples.

To integrate these additional tools with your project:

  1. Clone the demo repository:

    git clone https://github.com/ShenSeanChen/launch-mcp-demo.git
  2. Follow the installation instructions in the repository's README

  3. Update your .cursor/mcp.json to include the additional tools:

    {
      "mcpServers": {
        "stripe": {
          // Your existing Stripe configuration
        },
        "supabase": {
          // Your existing Supabase configuration
        },
        "weather": {
          "command": "/path/to/your/python/environment",
          "args": [
            "--directory",
            "/path/to/launch-mcp-demo/weather",
            "run",
            "weather.py"
          ]
        },
        "files": {
          "command": "/path/to/your/python/environment",
          "args": [
            "--directory",
            "/path/to/launch-mcp-demo/files",
            "run",
            "files.py"
          ]
        }
      }
    }
  4. Restart your Cursor editor to apply the changes

These additional tools can help enhance your development workflow and provide more capabilities to the AI assistant when working with your project.

πŸ“– Project Structure

β”œβ”€β”€ app/                  # Next.js 14 app directory
β”‚   β”œβ”€β”€ api/              # API routes
β”‚   β”‚   β”œβ”€β”€ email/send/   # Email sending API
β”‚   β”‚   β”œβ”€β”€ stripe/       # Stripe payment endpoints
β”‚   β”‚   └── user/         # User API endpoints
β”‚   β”œβ”€β”€ auth/             # Auth-related pages
β”‚   β”‚   β”œβ”€β”€ callback/     # handle auth callback
β”‚   β”œβ”€β”€ preview-email/    # Email template preview
β”‚   β”œβ”€β”€ dashboard/        # Dashboard pages
β”‚   β”œβ”€β”€ pay/              # Payment pages
β”‚   β”œβ”€β”€ profile/          # User profile pages
β”‚   β”œβ”€β”€ reset-password/   # Reset password pages
β”‚   β”œβ”€β”€ update-password/  # Update password pages
β”‚   β”œβ”€β”€ verify-email/     # Verify email pages
β”‚   β”œβ”€β”€ layout.tsx        # Root layout
β”‚   └── page.tsx          # Home page
β”œβ”€β”€ components/           # Reusable components
β”œβ”€β”€ contexts/             # React contexts
β”œβ”€β”€ emails/               # Email templates (React Email)
β”‚   └── templates/
β”œβ”€β”€ hooks/                # Custom React hooks
β”œβ”€β”€ services/             # Service layer (emailService, etc.)
β”œβ”€β”€ supabase/             # Supabase configuration
β”‚   β”œβ”€β”€ functions/        # Edge Functions
β”‚   └── scripts/setup/    # SQL migration scripts
β”œβ”€β”€ utils/                # Utility functions
β”œβ”€β”€ types/                # TypeScript type definitions
β”œβ”€β”€ public/               # Static assets
β”œβ”€β”€ styles/               # Global styles
└── .cursor/              # Cursor editor and MCP configurations
    β”œβ”€β”€ mcp.json.example  # Example MCP configuration
    └── mcp.json          # Your custom MCP configuration (gitignored)

πŸ› οΈ Built With

πŸ”§ Configuration

Tailwind Configuration

The template includes a custom Tailwind configuration with:

  • Custom colors
  • Dark mode support
  • Extended theme options
  • Custom animations

Authentication

Authentication is handled through Supabase with support for:

  • Email/Password
  • Google OAuth
  • Magic Links
  • Password Reset

Payment Integration

Stripe integration includes:

  • Subscription management
  • Trial periods
  • Webhook handling
  • Payment status tracking

🀝 Contributing

  1. Fork the repository
  2. Create your feature branch (git checkout -b feature/AmazingFeature)
  3. Commit your changes (git commit -m 'Add some AmazingFeature')
  4. Push to the branch (git push origin feature/AmazingFeature)
  5. Open a Pull Request

πŸ“ License

This project is licensed under the MIT License - see the LICENSE file for details.

πŸ™ Acknowledgments

  • Next.js team for the amazing framework
  • Vercel for the deployment platform
  • Tailwind CSS team for the utility-first CSS framework
  • Supabase team for the backend platform
  • Stripe team for the payment infrastructure
  • Resend team for the email infrastructure
  • Cursor team for the AI-powered editor and MCP capabilities
  • Anthropic for Claude AI and Claude Desktop integration
  • MCP framework developers for enabling extended AI capabilities

πŸ“« Contact

X - @ShenSeanChen

YouTube - @SeanAIStories

Discord - @Sean's AI Stories

Instagram - @SeanAIStories

Project Link: https://github.com/ShenSeanChen/launch-stripe-nextjs-supabase

πŸš€ Deploy

The easiest way to deploy your Next.js app is to use the Vercel Platform.

Deploy with Vercel


Made with πŸ”₯ by ShenSeanChen

About

Welcome to Sean's Open Source MVP Boilerplate Template for Production-Ready NextJS+Stripe+Supabase App.

Resources

License

Contributing

Stars

Watchers

Forks

Packages

No packages published