Skip to main content

How to Use Supabase

LightningAddon supports Supabase as a backend for authentication, database, and server-side flows. This guide walks you through setting it up.

Prerequisites

Step 1: Extension Environment

Add these to envs/.env.development (and envs/.env.production for builds):

VITE_SUPABASE_URL=https://your-project.supabase.co
VITE_SUPABASE_ANON_KEY=your-anon-key
VITE_STRIPE_PUBLISHABLE_KEY=pk_test_...
VITE_AUTH_PROVIDER=supabase

Get the Supabase URL and anon key from your project's Settings → API in the Supabase dashboard.

Step 2: Server Environment

Create envs/.env.supabase.local for your Supabase Edge Functions:

SUPABASE_URL=https://your-project.supabase.co
SUPABASE_SERVICE_ROLE_KEY=your-service-role-key
STRIPE_API_KEY=sk_test_...
STRIPE_PRICE_ID_MONTHLY=price_...
STRIPE_PRICE_ID_YEARLY=price_...
STRIPE_WEBHOOK_SIGNING_SECRET=whsec_...
RESEND_API_KEY=re_...
  • SUPABASE_SERVICE_ROLE_KEY: From Supabase Settings → API (never expose in the extension)
  • STRIPE_*: From Stripe Dashboard
  • RESEND_API_KEY: For sending welcome emails (optional)

Step 3: Run Supabase Locally

From the apps/supabase directory (or project root):

supabase functions serve --env-file ../../envs/.env.supabase.local

Or from the project root, adjust the path to your envs/ folder as needed.

Step 4: Deploy Edge Functions

supabase functions deploy

Set the secrets in Supabase Dashboard or via CLI:

supabase secrets set STRIPE_API_KEY=sk_live_...
supabase secrets set STRIPE_WEBHOOK_SIGNING_SECRET=whsec_...

What You Get with Supabase

FeatureImplementation
AuthSupabase Auth (email/password)
DatabasePostgres (SQL)
Server logicEdge Functions (Deno)
Stripe checkoutstripe-checkout function
Stripe portalstripe-manage-subscription function
Stripe webhookhandle-stripe-webhook function
Welcome emailResend (via webhook handler)
Session restoreCookie-based: sb-access-token + sb-refresh-token from chrome.cookies

Auto-Detection

If you don't set VITE_AUTH_PROVIDER, LightningAddon auto-detects based on which keys are present. If both Supabase and Firebase keys exist, set VITE_AUTH_PROVIDER=supabase explicitly.