Skip to content
Get the kit

Supabase

The kit ships two interchangeable backends. This guide covers the Supabase one: the same Hono API on an Edge Function, Postgres instead of Firestore, auth app_metadata instead of custom claims. The extension talks to either backend through the same routes and storage keys, so your components never know which stack is behind them.

Pick the stack in the setup wizard and the other one is pruned from your clone. Everything below assumes a Supabase clone. The project setup is below, and so are the payments commands.

The wizard’s Supabase step does the setup: it creates or picks the project, writes its URL and publishable key into apps/extension/.env, applies the schema, deploys the Edge Function, and switches on the auth settings the extension needs. What it asks and prints, and the one step left to you, a Google OAuth client: The Supabase project. Rerun it any time:

Terminal window
pnpm create extstart --supabase
  1. Create a project at supabase.com, then put its keys and the API URL into apps/extension/.env. The values are under Project Settings → API:

    apps/extension/.env
    WXT_SUPABASE_URL=https://<project-ref>.supabase.co
    WXT_SUPABASE_ANON_KEY=<publishable key>
    WXT_API_URL=https://<project-ref>.supabase.co/functions/v1/api

    The anon key is public by design, like a Firebase web config; row security is what protects the data.

  2. Push the schema. From the backend folder:

    Terminal window
    supabase link --project-ref <project-ref>
    Terminal window
    supabase db push

    This creates the tables, row security, and RPCs the kit expects.

  3. Configure auth in the dashboard (Authentication → Providers): enable Google, and for anonymous-first enable Anonymous sign-ins and manual linking. Under Email, turn off Confirm email, so a new account is signed in right away. Add the extension’s redirect URL, https://<extension-id>.chromiumapp.org/, to the project’s redirect URLs (Authentication → URL Configuration). chrome://extensions shows the ID on your extension’s card once it is loaded, and the key in apps/extension/extension-public-key.txt keeps it the same on every clone. A Firefox build adds its own redirect URL there too (Google sign-in on Firefox). Under Authentication → Emails, make the Reset password template show the code instead of the link: put {{ .Token }} where it says {{ .ConfirmationURL }}. The extension’s form takes that code (a link would land on a web page where nothing can finish the reset).

  4. Deploy the function. From the backend folder:

    Terminal window
    supabase functions deploy api

Then load the extension. Env values are baked in at build time: after any change to .env, restart pnpm dev and reload the extension.

The security contract is identical to the Firebase path, enforced by Postgres row security instead of Firestore rules:

  • Entitlements live in the customers table, written only by the payment provider’s webhook through a compare-and-swap RPC (apply_webhook_event, which commits the event’s writes with its dedupe marker, so a retried event never applies twice). Clients can read their own row and can never write it.
  • Claims mirror: the webhook mirrors the paid state into auth app_metadata, the Supabase equivalent of custom claims.
  • Usage lands in the usage table via POST /gate/events, a per-account record of feature use. Card trials (trialUsed) and credit balances are enforced on the customer’s row, not from this table.
  • Prices resolve by lookup_key server-side. The extension never sends a price id or an amount.
  • backend/supabase/functions/api/: the Edge Function. app.ts wires the routes to Supabase (token check, credit spend, usage, sign-out) and adds the checkout return pages, and index.ts starts it; store.ts implements the entitlement-store and claims-writer ports on Postgres.
  • backend/supabase/tests/: the routes on this wiring, the store, and the Stripe signature check against an in-memory client. Run DENO_NO_PACKAGE_JSON=1 deno test backend/supabase/tests from the repo root; CI runs it too.
  • backend/supabase/functions/api/core/: routes.ts, the routes both backends serve, and the billing and gate modules, the payment providers included. A route of your own can go in app.ts, next to the return pages. In a Supabase clone these are plain source: edit them in place. (In the kit, where both backends ship, they are copies of backend/functions/src that scripts/sync-core.mjs keeps in sync; the wizard’s Supabase prune removes the script and the do-not-edit headers.)
  • backend/supabase/migrations/: schema, row security, and the RPCs (apply_webhook_event, apply_customer_txn, increment_usage). When you update the kit, apply its new migrations (supabase db push) before deploying its function.

Entitlements and broadcasts stream over Supabase Realtime: the migration adds both tables to the supabase_realtime publication, and the background subscribes. Every resubscribe runs a catch-up fetch, so state written while the service worker slept lands on wake. The UI keeps reading storage.local snapshots either way. The migration also inserts the example broadcast (row welcome), the banner the popup shows first; edit or delete it in the dashboard when you have seen it (what it is).

WXT_BACKEND=supabase selects the stack at build time (the wizard sets it in apps/extension/.env). The #backend alias swaps the background wiring, so the Firebase SDK never enters a Supabase bundle. The client lives in apps/extension/utils/supabase.ts: sessions in the extension’s IndexedDB, PKCE, no refresh timers. Sign-in uses @extensionstart/core-auth/supabase: Google through chrome.identity.launchWebAuthFlow and anonymous-first linking with the uid preserved.

The wizard’s payments step works on this stack too: Enter at Set up payments with <provider> now? right after the project step, or any time:

Terminal window
pnpm create extstart --payments-setup

It stores the provider key, PAYMENT_PROVIDER, the sandbox flag, and BILLING_TRIAL_DAYS as function secrets, seeds the catalog, sets up the webhook (Stripe’s by API; for Polar or Paddle it prints the URL, you create the webhook in the dashboard and paste its secret), and checks that the API answers (what it asks). Nothing is deployed: the function reads its secrets on the next request. Checkout returns to pages the function serves itself, …/functions/v1/api/return/success, /return/cancel, and /return/portal, the same pages Firebase Hosting serves on the other stack; set BILLING_SUCCESS_URL, BILLING_CANCEL_URL, or BILLING_PORTAL_RETURN_URL as secrets to send users to your own site instead.

The catalog is account-level at the provider, so the same seed scripts apply on both stacks. They live in backend/payments and take the key from the environment. From the repo root, for Stripe:

Terminal window
STRIPE_SECRET_KEY=sk_test_… node backend/payments/stripe/seed-products.mjs

Then from backend:

Terminal window
supabase secrets set STRIPE_SECRET_KEY=sk_test_… PAYMENT_PROVIDER=stripe BILLING_TRIAL_DAYS=0

BILLING_TRIAL_DAYS is the trial checkout starts: 0 unless paywall.config.ts offers trial: { days, card: true }, and then those days.

Create the webhook in the Stripe dashboard pointing at https://<project-ref>.supabase.co/functions/v1/api/billing/webhook with the events listed in backend/payments/stripe/webhook.mjs, then store its secret:

Terminal window
supabase secrets set STRIPE_WEBHOOK_SECRET=whsec_…

Polar and Paddle, when your clone kept one of them, work the same way: node backend/payments/polar/seed-products.mjs or node backend/payments/paddle/seed-products.mjs with POLAR_ACCESS_TOKEN or PADDLE_API_KEY in the environment (plus POLAR_SANDBOX=true or PADDLE_SANDBOX=true for a sandbox account, there and as a secret), their token or key and webhook secret through supabase secrets set, and the webhook URL is …/functions/v1/api/billing/webhook. Set PAYMENT_PROVIDER=polar or PAYMENT_PROVIDER=paddle as a secret too: unset, the function runs Stripe.

Dropped the billing module? Set the flag and deploy with no Stripe secrets at all:

Terminal window
supabase secrets set BILLING_DISABLED=true
supabase functions deploy api

The billing routes answer with a clean disabled state and everything else keeps working.