Short answer
If your app decides who is a paying customer with an if statement in React, the paid data is still served to anyone who asks the API directly, and a subscription row the user can write is a free upgrade button. Keep subscription status in a table only your payment webhook writes, check it in the policies of paid tables through a security definer helper, and treat the frontend check as display only.
Ask an AI about this page:ChatGPTClaude
On this page
A subscription check that only lives in React hides the paywall’s content, but it doesn’t protect it. If the paid rows are readable by every signed-in user, a free account can fetch them straight from the API. If users can write their own subscription row, they can simply mark themselves as paying. It is rated high: no other user’s data leaks, but anyone with a free account gets what others pay for, and you lose revenue without noticing.
Why it matters
Here is a typical shape, taken from a template library:
create table public.subscriptions (
user_id uuid primary key references auth.users (id) on delete cascade,
status text not null default 'inactive',
current_period_end timestamptz
);
alter table public.subscriptions enable row level security;
create policy "Users manage their subscription"
on public.subscriptions for all
to authenticated
using ((select auth.uid()) = user_id);
create table public.pro_templates (
id serial primary key,
title text not null,
body text not null
);
alter table public.pro_templates enable row level security;
create policy "Signed-in users can read templates"
on public.pro_templates for select
to authenticated
using (true);The React page loads the subscription, and if status isn’t active it shows an upgrade screen instead of the templates. Both protections are in the browser. The templates policy lets every signed-in user read every row, so a free user who calls supabase.from("pro_templates").select() from the console gets the full library. And the subscription policy covers all actions on the user’s own row, so the same user can upsert status = 'active' and a period end in 2099, and the app’s own check now agrees they are a customer. This is client-side enforcement of server-side security (CWE-602 (opens in a new tab)), which OWASP files under insecure design.
How to find it in your app
Look for the places where the frontend decides about the plan: search for status === "active", isPro, plan, subscription and paywall. For every paid screen, note which table or function provides its data. Then check two things in the SQL Editor: which policies let signed-in users write subscription-like tables, and which paid tables are readable by everyone signed in:
select tablename, policyname, cmd, qual
from pg_policies
where schemaname = 'public'
and (
(tablename ~* 'subscription|plan|billing|entitlement' and cmd in ('INSERT', 'UPDATE', 'ALL'))
or (cmd in ('SELECT', 'ALL') and qual = 'true' and 'authenticated' = any (roles))
)
order by tablename, policyname;The first kind of row is a self-service upgrade. The second kind is fine for content every user may see, and a leak for anything behind your paywall.
How to fix it
Make the subscription read-only for users, let only the payment webhook write it, and check it inside the policy of every paid table. In a new migration:
drop policy "Users manage their subscription" on public.subscriptions;
revoke insert, update, delete on table public.subscriptions from anon, authenticated;
create policy "Users can read their subscription"
on public.subscriptions for select
to authenticated
using ((select auth.uid()) = user_id);
create schema if not exists private;
create or replace function private.has_active_subscription()
returns boolean
language sql
security definer
set search_path = ''
stable
as $$
select exists (
select 1 from public.subscriptions s
where s.user_id = (select auth.uid())
and s.status in ('active', 'trialing')
and s.current_period_end > now()
);
$$;
drop policy "Signed-in users can read templates" on public.pro_templates;
create policy "Subscribers can read templates"
on public.pro_templates for select
to authenticated
using ((select private.has_active_subscription()));Your Stripe webhook, running in an edge function with the secret key, is now the only writer of subscriptions. Stripe’s own guide says to grant access on invoice.paid when the subscription is active, and to revoke it when the status turns canceled or unpaid; store that status and the period end. The webhook must verify Stripe’s signature first, or anyone can post a fake “paid” event (see Stripe webhook without signature check). Keep the React check for a friendly upgrade screen; it is just not the lock any more. Paid features that run on the server, like AI calls, need the same check in their edge function. The paywall bypass guide walks through the other routes around a paywall.
Paid content in this app is protected only by a subscription check in React. Add a new Supabase migration that: removes every insert, update and delete policy on public.subscriptions and revokes insert, update and delete on it from anon and authenticated, leaving a select policy so users read only their own row; creates private.has_active_subscription() as a security definer SQL function with set search_path = ‘’ that returns true when the caller’s subscription has status active or trialing and current_period_end in the future; replaces the select policy on public.pro_templates (and every other paid table) so only callers for whom that function returns true can read rows.
Make sure the Stripe webhook edge function is the only code that writes public.subscriptions, using the secret key after verifying the Stripe signature. Do not write subscription status from the browser or from the checkout success page.
Check that the fix works
Act as a free user and try both routes, reading paid rows and upgrading yourself:
begin;
set local role authenticated;
set local request.jwt.claims = '{"sub": "22222222-2222-2222-2222-222222222222", "role": "authenticated"}';
select count(*) as templates_visible from public.pro_templates;
insert into public.subscriptions (user_id, status, current_period_end)
values ('22222222-2222-2222-2222-222222222222', 'active', '2099-01-01');
rollback;With a real free user’s ID in both places, the count must be 0 and the insert must fail with permission denied for table subscriptions. Run the block up to the select with a paying user’s ID: they must see every template. Finally, cancel a test subscription in Stripe’s test mode and confirm that the same user loses access after the webhook has run. For the related problem of credits and prices, see credits granted on the client.
Frequently asked questions
Can users really see my paid content if the paywall is in place?
If the paid rows are readable by every signed-in user, yes. The paywall only stops your own app from asking for them. A request to the Data API with the public key and a free account’s session returns them.
Where should the subscription status come from?
From your payment provider, delivered to your server. With Stripe, that means a webhook that verifies the signature and then writes the status with the secret key. Never from the success page the browser lands on after checkout.
Do I need to check the subscription in edge functions too?
Yes. Any paid feature that runs on the server, such as an AI call, must check the subscription there before doing the work, using the caller’s verified session.
What happens when a subscription is cancelled?
Your webhook updates the status, and because the policy reads the status on every query, access ends with the next request. No frontend change needed.
Sources
- 1.Row Level Security — Supabase Docs
- 2.Database functions — Supabase Docs
- 3.Using webhooks with subscriptions — Stripe Docs
- 4.CWE-602: Client-Side Enforcement of Server-Side Security — MITRE
- 5.A04 Insecure Design — OWASP Top 10