Supabase Row Level Security for beginners
Supabase gives your front end direct access to the database through an API. The thing standing between a visitor and every row in your tables is Row Level Security (RLS). If it is off on a table in an exposed schema, anyone with your public key can read, and often change, that table.
Turn it on
alter table public.notes enable row level security;
With RLS on and no policies, nobody can read or write through the API. That is the safe default; you then add policies that allow exactly what each user needs.
A simple “own rows only” policy
create policy "read own notes" on public.notes
for select using (auth.uid() = user_id);
create policy "insert own notes" on public.notes
for insert with check (auth.uid() = user_id);
auth.uid() is the signed-in user; user_id is a column on the row. Add update and delete policies the same way, only if users should be able to do those things.
Keys: what is safe where
- The anon / publishable key is designed to be public, but only safe if RLS is enabled everywhere.
- The service role key bypasses RLS. It belongs only on a server, never in front-end code or in a repository.
Test it
Sign in as user A, then try to fetch user B’s rows by ID. Also try the API with no login. Both should return nothing. Supabase’s security advisor in the dashboard also flags tables without RLS.
This is a starting point, not a full audit. Policies for shared data, teams and admin roles need more thought.
Want the whole checklist?
Vibe101 is an interactive checklist, 11 chapters from idea to launch. The Security first chapter is free.
Published by the author of Vibe101, a paid checklist. This is general information, not legal advice or a security audit.