Tamper-proof paywall kit.
I once found a user in production with pro data and zero purchases because a patched client returned true on isPro. Move the truth into Postgres.
How it works
Keep the RevenueCat SDK in your mobile app so the paywall UI stays fast and offline friendly. Mirror every webhook event into a locked public.entitlements table so Postgres Row Level Security enforces paid access on every query.
Mirrors RevenueCat subscription state into Postgres. Authenticated clients can only SELECT their own row; only service_role writes.
create table public.entitlements (
user_id uuid not null references auth.users(id) on delete cascade,
entitlement_id text not null, -- e.g. 'pro'
is_active boolean default false not null,
product_id text,
store text, -- APP_STORE | PLAY_STORE | STRIPE
expires_at timestamptz,
updated_at timestamptz default now() not null,
primary key (user_id, entitlement_id)
);
alter table public.entitlements enable row level security;
grant select on public.entitlements to authenticated;
grant all on public.entitlements to service_role;
create policy "Users read own entitlements"
on public.entitlements for select
to authenticated
using ((select auth.uid()) = user_id);
-- Gate any premium table with an exists() check:
-- create policy "Pro members read premium items"
-- on public.premium_items for select
-- to authenticated
-- using (
-- exists (
-- select 1 from public.entitlements e
-- where e.user_id = (select auth.uid())
-- and e.entitlement_id = 'pro'
-- and e.is_active
-- and (e.expires_at is null or e.expires_at > now())
-- )
-- );Free zip bundleZIP, 3 KB
Download the RevenueCat + Supabase RLS Paywall Kit
Four drop-in files with deploy commands and a pgTAP test you can run in GitHub Actions.
- 00001_entitlements.sql + 00002_revoke_blanket_grants.sql
- revenuecat-webhook/index.ts (constant-time auth, idempotent upsert)
- tests/entitlements_test.sql (pgTAP assertions against SQLSTATE 42501)
One email each Sunday, unsubscribe in one click. Or skip the box: the file is right here. Hit a Supabase grants or webhook issue? Reply to the email and I will help you debug it for free.
Extracted straight from TanBase
Need the full Flutter + Supabase plumbing?
This migration and webhook come directly from TanBase, along with account deletion, force-update gates, multi-device FCM push, RTL smoke tests, and 50+ pgTAP assertions.
See TanBase on tanfust.comOne email each Sunday.
The new video and the real numbers behind it.