What does 'new row violates row-level security policy for table' mean?
RLS is on for the table, but no INSERT or UPDATE policy's WITH CHECK clause allows the row you sent. Add a policy that lets a signed-in user write only rows they own (for example auth.uid() = user_id). Don't turn RLS off or use with check (true).
Last updated 2026-11-25 · Reviewed by ProofForge
The exact error
new row violates row-level security policy for table "todos"
(Postgres code 42501: HTTP 403 for signed-in requests, 401 for anon)Why it happens
- Row Level Security is enabled and there is no INSERT policy, or the policy's
WITH CHECKis false for this row. - The request runs as
anonbecause the user's session wasn't attached, soauth.uid()is null. - The row's
user_idisn't set, or is set to someone else's id. - You call
.insert(...).select(). The returned row also needs a matching SELECT policy.
How to fix it
- Confirm the user is signed in before writing (
supabase.auth.getUser()returns a user). - Default the owner column to the caller and add an owner-scoped INSERT policy:
- If the app updates rows, add an UPDATE policy with both
USINGandWITH CHECK. - If you insert and read back with
.select(), add the matching SELECT policy.
alter table public.todos enable row level security;
alter table public.todos alter column user_id set default auth.uid();
create policy "insert own rows" on public.todos
for insert to authenticated
with check ((select auth.uid()) = user_id);
create policy "update own rows" on public.todos
for update to authenticated
using ((select auth.uid()) = user_id)
with check ((select auth.uid()) = user_id);
create policy "read own rows" on public.todos
for select to authenticated
using ((select auth.uid()) = user_id);Check it's fixed
Insert as user A (works), then try to insert a row with user B's user_id while signed in as A (fails). Run a ProofForge scan to confirm anonymous visitors can't read the table.
Check your live app
A free, read-only public-surface scan. It cannot diagnose private sessions or every cause described above.
FAQ
Can I just disable RLS to make the error go away?
No. With RLS off, anyone with your public anon or publishable key can read and write the table through the Data API.
Why does the insert work in the SQL editor but not in the app?
The SQL editor runs as a privileged role that bypasses RLS. Your app runs as anon or authenticated, so policies apply.
Is with check (true) safe?
Only for data anyone may write, such as a public contact form, and even then pair it with rate limits. For user data it lets every signed-in user write any row.