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.
Set up
Section titled “Set up”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:
pnpm create extstart --supabaseThe manual path (no wizard)
Section titled “The manual path (no wizard)”-
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.coWXT_SUPABASE_ANON_KEY=<publishable key>WXT_API_URL=https://<project-ref>.supabase.co/functions/v1/apiThe anon key is public by design, like a Firebase web config; row security is what protects the data.
-
Push the schema. From the
backendfolder:Terminal window supabase link --project-ref <project-ref>Terminal window supabase db pushThis creates the tables, row security, and RPCs the kit expects.
-
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://extensionsshows the ID on your extension’s card once it is loaded, and the key inapps/extension/extension-public-key.txtkeeps 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). -
Deploy the function. From the
backendfolder: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 same authority map
Section titled “The same authority map”The security contract is identical to the Firebase path, enforced by Postgres row security instead of Firestore rules:
- Entitlements live in the
customerstable, 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
usagetable viaPOST /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_keyserver-side. The extension never sends a price id or an amount.
Layout
Section titled “Layout”backend/supabase/functions/api/: the Edge Function.app.tswires the routes to Supabase (token check, credit spend, usage, sign-out) and adds the checkout return pages, andindex.tsstarts it;store.tsimplements 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. RunDENO_NO_PACKAGE_JSON=1 deno test backend/supabase/testsfrom 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 inapp.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 ofbackend/functions/srcthatscripts/sync-core.mjskeeps 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.
Live state without polling
Section titled “Live state without polling”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).
The extension build
Section titled “The extension build”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.
Payments
Section titled “Payments”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:
pnpm create extstart --payments-setupIt 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 manual path (no wizard)
Section titled “The manual path (no wizard)”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:
STRIPE_SECRET_KEY=sk_test_… node backend/payments/stripe/seed-products.mjsThen from backend:
supabase secrets set STRIPE_SECRET_KEY=sk_test_… PAYMENT_PROVIDER=stripe BILLING_TRIAL_DAYS=0BILLING_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:
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.
Billing off, or on later
Section titled “Billing off, or on later”Dropped the billing module? Set the flag and deploy with no Stripe secrets at all:
supabase secrets set BILLING_DISABLED=truesupabase functions deploy apiThe billing routes answer with a clean disabled state and everything else keeps working.