Skip to main content

GitHub Repository

Complete source code and setup guide
Checkout the complete starter kit for supabase
A minimal subscription starter kit built with Next.js, Supabase, and Dodo Payments. This boilerplate helps you quickly set up a subscription-based SaaS with authentication, payments, and webhooks.
Dodo Payments Supabase Subscription Starter

Quick Setup

1. Prerequisites

Get your project ref from Supabase Dashboard → Project Settings

3. Database Setup

  1. Go to your Supabase Dashboard
  2. Open the SQL Editor
  3. Create a new query
  4. Copy and paste the entire contents of schema.sql
  5. Run the query

4. Set Initial Secrets

Supabase automatically provides SUPABASE_URL and SUPABASE_SERVICE_ROLE_KEY at runtime.
Note: We’ll set DODO_PAYMENTS_WEBHOOK_KEY after deployment once you have your webhook URL.

5. Deploy

The function is already set up in functions/webhook/index.ts - just deploy it:

6. Get Your Webhook URL

Your webhook URL is:

7. Register Webhook in DodoPayments Dashboard

  1. Go to DodoPayments Dashboard → Developer → Webhooks
  2. Create a new webhook endpoint
  3. Configure your webhook URL as the endpoint
  4. Enable these subscription events:
    • subscription.active
    • subscription.cancelled
    • subscription.renewed
  5. Copy the Signing Secret

8. Set Webhook Key & Redeploy

What It Does

Processes subscription events and stores them in Supabase PostgreSQL:
  • subscription.active - Creates/updates customer and subscription records
  • subscription.cancelled - Marks subscription as cancelled
  • subscription.renewed - Updates next billing date

Key Features

Signature verification - Using the dodopayments library
Idempotency - Prevents duplicate processing with webhook IDs
Event logging - Complete audit trail in webhook_events table
Error handling - Logged and retryable
Note: This implementation demonstrates handling three core subscription events (subscription.active, subscription.cancelled, subscription.renewed) with minimal fields. You can easily extend it to support additional event types and fields based on your requirements.

Configuration Files

Database Schema

Tables created:
  • customers - Email, name, dodo_customer_id
  • subscriptions - Status, amount, next_billing_date, linked to customers
  • webhook_events - Event log with webhook_id for idempotency

Implementation Code

How It Works

The Deno-based Edge Function:
  1. Verifies signature - Uses dodopayments library for HMAC-SHA256 verification
  2. Checks idempotency - Looks up webhook ID to prevent duplicate processing
  3. Logs the event - Stores raw webhook data in webhook_events table
  4. Processes updates - Creates or updates customers and subscriptions via Supabase client
  5. Handles errors - Logs failures and marks event for retry

Testing

Local development:
The --no-verify-jwt flag is required because webhooks don’t include JWT tokens. Security is provided by webhook signature verification.
View logs:
Or in Supabase Dashboard → Edge Functions → webhook → Logs tab Configure in DodoPayments Dashboard:
  1. Go to Developers → Webhooks
  2. Add endpoint with your Supabase URL
  3. Enable: subscription.active, subscription.cancelled, subscription.renewed

Common Issues

Resources

Last modified on May 19, 2026