Skip to content

What does 'new row violates row-level security policy for table' mean?

Short answer

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

text
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 CHECK is false for this row.
  • The request runs as anon because the user's session wasn't attached, so auth.uid() is null.
  • The row's user_id isn'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

  1. Confirm the user is signed in before writing (supabase.auth.getUser() returns a user).
  2. Default the owner column to the caller and add an owner-scoped INSERT policy:
  3. If the app updates rows, add an UPDATE policy with both USING and WITH CHECK.
  4. If you insert and read back with .select(), add the matching SELECT policy.
sql
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.

Read-only. No writes or row contents.

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.

Sources

Related

Read as Markdown · Scan methodology