TL;DR: Row Level Security (RLS) in Supabase is the difference between a social app that is secure by default and one that leaks user data the moment someone opens the browser console. I run a TikTok-style short-video app, SARAIKI STAR, on Supabase with 140 videos, likes, comments, follows, and live streams — all protected by RLS policies on 12 tables. The rules that matter most: enable RLS on every table before your first user signs up, write policies around auth.uid(), keep public reads narrow, and never trust the client to enforce permissions.

Why RLS is not optional for a social app

A short-video app is a worst case for security. Every user can read almost everything (public videos, profiles, comments) but should only write their own rows. If your database has no row-level rules, anyone with your Supabase anon key — which is public by design, it ships inside your app — can read, insert, update, or delete anything your API allows. I have seen developers ship apps where a single curl command could delete another user's videos. RLS is the one feature that stops that.

Supabase exposes your Postgres database through PostgREST. RLS policies are Postgres rules that run on every query, no matter who calls it. When RLS is enabled on a table and no policy matches, the row is invisible — not an error, just gone. That "deny by default" behaviour is exactly what you want.

The setup I actually run in production

My app, SARAIKI STAR, is a Flutter short-video platform backed by a dedicated Supabase project. The schema has 12 tables — users, videos, follows, likes, saves, comments, live sessions, live comments, and a few supporting tables — plus a Postgres function that ranks the For You feed. Every table has RLS enabled. Here is how I think about each policy.

1. Public reads, private writes

The feed is public: anyone can watch videos without signing in. So the videos table allows SELECT for everyone, including anonymous users:

create policy "Public videos are viewable by everyone" on videos for select using (true); 

But inserts, updates, and deletes are owner-only:

create policy "Users can insert their own videos" on videos for insert with check (auth.uid() = owner_id); create policy "Users can delete their own videos" on videos for delete using (auth.uid() = owner_id); 

That single pattern — public read, auth.uid() = owner_id write — covers most social-app tables. It took me about 20 minutes to write for all 12 tables, and it has blocked every unauthorised write attempt since.

2. Never let the client decide who owns a row

A common beginner mistake is trusting a user_id field sent from the app. An attacker can send anyone's ID. Instead, set the owner server-side with a default or a trigger:

alter table videos alter column owner_id set default auth.uid(); 

Now even if a malicious client sends a forged owner_id, the database overwrites it with the real authenticated user. Your Flutter code never has to remember to set it.

3. Rate limits belong in the database, not the app

My app limits users to 3 video uploads per day. I first implemented this as a check in the Flutter app — and immediately realised anyone could bypass it by calling the API directly. The fix was a Postgres trigger that counts today's uploads and rejects the insert when the limit is hit:

create or replace function enforce_daily_limit() returns trigger as $$ begin if (select count(*) from videos where owner_id = auth.uid() and created_at >= date_trunc('day', now())) >= 3 then raise exception 'Daily upload limit reached'; end if; return new; end; $$ language plpgsql; 

The same trick works for comment spam, follow spam, and any other abuse vector. If a rule matters, enforce it where it cannot be bypassed.

4. Keep the anon key harmless

The Supabase anon key is not a secret — it is embedded in every client app. Treat it as public. The security boundary is RLS, not the key. I audit this by running queries as the anon role and confirming that:

  • Anonymous users can read public videos, profiles, and comments.
  • Anonymous users cannot insert, update, or delete anything.
  • Authenticated users cannot touch rows they do not own.

If any of those three checks fails, the app does not ship. This 5-minute audit has caught two policy mistakes before they reached production.

5. Don't put secrets in the app — put them in the backend

My live-streaming feature needs Agora RTC tokens. Tokens are signed with a secret certificate, so generating them in the app would leak the certificate. Instead, a small serverless function signs tokens, and the app calls that function. The same rule applies to any privileged operation: if it needs a service-role key or a third-party secret, it lives in an Edge Function or a serverless endpoint — never in Flutter code, never in the repository.

The performance question everyone asks

"Does RLS slow down my feed?" In practice, no — not at the scale most indie apps run at. My For You feed is ranked by a Postgres function that scores videos on likes, comments, shares, saves, and views, with freshness decay and boosts for followed creators and new videos. It reads from tables that all have RLS enabled, and it still returns a page in well under 200 milliseconds for a catalog of 140 videos. The policies add a filter to each query; Postgres handles that cheaply as long as your owner_id and foreign-key columns are indexed.

Two performance rules I follow:

  1. Index every column a policy filters on — owner_id, video_id, user_id. An unindexed policy check is the only way RLS gets slow.
  2. Use security definer functions carefully — my feed-ranking function bypasses RLS by design (it is read-only and only returns public video data). A security definer function that writes data is a hole; audit each one.

A checklist you can steal

Before you launch any Supabase-backed social app, verify these:

  1. RLS enabled on every table — including the ones you think are internal.
  2. Public SELECT only where the data is genuinely public.
  3. Every write policy checks auth.uid() against an owner column.
  4. Owner columns default to auth.uid() server-side.
  5. Rate limits and abuse guards enforced by triggers, not app code.
  6. Secrets and privileged operations live in Edge Functions, not the client.
  7. An anonymous-role audit passes: read public data, write nothing.

Get those seven right and your app is secure by default — not by hope.

FAQ

Is Supabase RLS enough, or do I still need backend validation?
RLS is your database-level guarantee, and for most indie apps it is enough for data access control. Business rules that span multiple tables (payments, complex moderation) still belong in Edge Functions or a small API. Use both: RLS for access, functions for logic.

Does enabling RLS break the Supabase dashboard or the service role?
No. The service-role key bypasses RLS by design, so admin scripts and migrations still work. The dashboard uses the service role too. Only anon and authenticated client keys are restricted.

Can I use RLS with a public feed and anonymous users?
Yes. Policies can allow SELECT for the anon role while restricting writes to authenticated users. That is exactly how my app lets guests watch videos without an account while keeping every write behind sign-in.

How long does it take to add RLS to an existing app?
For a 12-table social app, about an hour including testing. For a new app, minutes — write the policies in the same SQL file as your schema so security ships with the tables, not after them.

Build on this, don't start from zero

Everything above is the exact backend I ship in ClipFlow — the complete Flutter + Supabase source code for a TikTok-style short-video app, including the 12-table schema, all RLS policies, the For You ranking function, Google sign-in, publishing with on-device compression, likes, comments, follows, inbox, and live streaming. You bring a free Supabase project; the one-file SQL schema builds the whole backend in about 15 minutes.

You can see the apps I have shipped with this stack — SARAIKI STAR, MyRide, ToolSuiteX, and more — on my portfolio, and my open-source work on GitHub.

If you are building a social app on Supabase, enable RLS today — before your first user, not after your first incident.