new row violates row-level security policy for table (SQLSTATE 42501)
appears when:After RLS is enabled on a table but no INSERT policy has been written for the authenticated role
Supabase RLS blocking insert
Postgres defaults to deny when RLS is on. Every INSERT, SELECT, UPDATE, DELETE is blocked until you write a policy.
INSERT policy whose WITH CHECK evaluates true for the row. Create a policy FOR INSERT TO authenticated WITH CHECK (auth.uid() = user_id) and a matching SELECT policy so the chained .select() can read the row back.How do I fix Supabase RLS blocking insert?
01-- Single-tenant ownership pattern (most AI apps start here)02create policy "users insert own rows"03on public.tasks04for insert05to authenticated06with check (auth.uid() = user_id);07 08-- Default auth.uid() so the client cannot forget to set user_id09alter table public.tasks10alter column user_id set default auth.uid();11 12-- Verify in SQL editor13set role authenticated;14insert into public.tasks (title) values ('test') returning *;Not a developer? We fix this for you at a fixed price: $299 emergency triage, done in 48 hours or fully refunded. Not sure what else is broken? Send the repo for the $49 audit.
What if the quick fix doesn't work?
01 · Add the matching SELECT policy
01create policy "users read own rows"02on public.tasks03for select04to authenticated05using (auth.uid() = user_id);02 · Multi-tenant: join through memberships
01create policy "members insert org rows"02on public.tasks03for insert04to authenticated05with check (06 organization_id in (07 select organization_id from memberships08 where user_id = auth.uid()09 )10);03 · Write a pgTAP regression test
01-- tests/rls_tasks.sql — asserts cross-tenant writes fail02begin;03select plan(1);04 05set local role authenticated;06set local "request.jwt.claims" = '{"sub":"user-a-uuid"}';07 08select throws_ok(09 $$insert into public.tasks (user_id, title) values ('user-b-uuid', 'test')$$,10 '42501',11 'cross-user insert must be blocked by RLS'12);13 14select * from finish();15rollback;Upserts, triggers and storage buckets
An upsert (.upsert(), which runs INSERT … ON CONFLICT DO UPDATE) needs more than an INSERT policy. Postgres checks the proposed row against the INSERT policy’s WITH CHECK, checks it against the SELECTpolicies, and if the update path is taken, checks the existing row against the UPDATE policy’s USING and the new row against its WITH CHECK. Unlike a plain UPDATE, a failed check here throws an error rather than skipping the row. So an upsert that fails while a plain insert works usually means a missing SELECT or UPDATE policy.
A trigger that writes to a second table, such as an audit log or a profile row, runs that write as the calling role by default, so the second table needs its own policy. Marking the trigger function security definerruns it with its owner’s rights instead; Supabase’s docs note that such a function only skips RLS when its owner can. Keep those functions out of schemas the API exposes.
Storage uploads hit the same error because files are rows in storage.objects. Supabase’s Storage docs say no uploads are allowed to a bucket without RLS policies, that an upload needs only an INSERT policy, and that overwriting with upsert also needs SELECT and UPDATE. Their per-user folder example:
create policy "users upload to own folder"
on storage.objects
for insert
to authenticated
with check (
bucket_id = 'my_bucket_id'
and (storage.foldername(name))[1] = (select auth.jwt()->>'sub')
);Testing policies as different users
The SQL editor runs as a privileged role, so a test there proves nothing until you switch role. Run the quick-fix block above (set role authenticated) for a basic check, then the pgTAP test in the fixes above, which sets one user’s sub claim and asserts that writing a row owned by a second user fails with 42501. Add a case where the same user inserts their own row and succeeds. Test the logged-out case too, as anon, because auth.uid() is null there. In the browser, sign in as two real test accounts and repeat the insert from each; the Network tab should show a 201 for the owner and an error for the other.
The dangerous fix: disabling RLS or using the service role key
Warning: do not ship the service role key to the browser.
Two fixes make this error disappear and both remove your protection. Disabling RLS lets anyone with your public key, which is visible in your frontend bundle, read and write the table. Putting the service_roleor secret key in client code does the same with full admin rights: Supabase’s docs say to use a secret key only for administrative tasks that need to bypass RLS and never in the browser, and its Storage docs say service keys bypass RLS entirely. If the key has already shipped in a build, rotate it.
The service role does have a correct place. A server-side Edge Function or API route can use it to write rows the browser should never insert directly, such as contact form submissions. In that design a security scanner may flag “anon cannot insert” as broken RLS, but that is the intended result: the browser calls the function, the function validates and inserts. Confirm that no browser code inserts into the table, and that the key lives only in the function’s secrets, before you dismiss the flag.
Fixing it inside Lovable and Bolt apps
In a Lovable or Bolt app the policies live in the Supabase database behind the app, not in the editor’s preview. Open the table’s policy list (the Supabase dashboard, or the builder’s own database view if it manages the project for you), find the cause in the table above, and apply the SQL as a migration so the fix is in the repo rather than only in the dashboard. If you ask the builder’s AI to fix it, read the policy it writes: a with check (true) or a disabled RLS toggle clears the error by removing the protection. Then re-run the two-user test. Our guide to Lovable security issues covers the other holes these apps tend to ship with, and the Supabase auth and database fixes hub collects the related errors.
When to get a security audit
One table with one ownership column is a job you can finish with this page. Get a second pair of eyes when the schema has many tables, organization or team membership, storage buckets with private files, or any place the service role key might have reached the client. Those are the cases where a policy that “works” can still leak rows to another user. For background on how vibe coding security risks show up in production, start there. Not sure your RLS is safe? Send your repo for the $49 async repo audit, or compare code audit services for a deeper review.
Supabase and Postgres documentation checked 4 November 2026.
Send your app URL. A senior engineer records a 10-minute teardown.
Free, and fully async — no call to book. A senior engineer walks your app on video: what’s broken, what’s risky, what to fix first. In your inbox within 24 hours. Want the code read line by line instead? Send the repo for the $49 audit.
Why do AI-built apps hit Supabase RLS blocking insert?
Lovable, Bolt, Base44, and Cursor all ship apps that talk to Supabase, usually straight from the browser with the public (anon or publishable) key. Every one of those requests runs as the anon or authenticated role, and both are evaluated against RLS. Server code holding the service_role or secret key skips RLS when the request carries no user token, so the same insert can work in a script or Edge Function and fail in the app.
Postgres default when RLS is enabled and no policy matches is deny. Your INSERT returns SQLSTATE 42501 with the message “new row violates row-level security policy for table”. If the INSERT is chained to .select(), the returned row must also pass a SELECT policy; the Postgres docs say such rows are never silently dropped, so a missing SELECT policy raises the same error even when the INSERT policy is correct. A second quiet cause: when no user is signed in, auth.uid() returns null, and null = user_id is never true.
The third variant is a policy that exists but checks the wrong thing. A FOR INSERT policy can only carry WITH CHECK; a FOR ALL policy with only a USING clause has that expression reused as the insert check, and WITH CHECK (true) lets any signed-in user write rows for anyone. The policy looks written and the table looks protected, but inserts fail, or succeed for rows they should not. Working through the row-by-row RLS audit checklist catches this class, because it makes you read USING and WITH CHECK separately on every policy instead of accepting that a policy exists at all.
One bypass sits outside the policy set entirely: the service_rolekey ignores RLS by design, so if that key leaks the table is readable no matter what you wrote. Vercel’s April 2026 incident exposed non-sensitive environment variables — which is exactly where most AI-built apps keep that key — so it is worth knowing when the leak is not in your policies. To rewrite the policies for several tables at once, paste your schema into the free Supabase RLS policy generator, which also writes pgTAP tests that expect 42501 on another user’s rows. And once a schema has more tables than you can realistically read policy-by-policy, you can have an engineer read the whole policy set against the schema in one pass rather than table by table.
Diagnose Supabase RLS blocking insert by failure mode
Four causes cover almost every version of this error. Read the policy list for the table in the dashboard, then match what you see to a row.
| Cause | How to spot it | Fix |
|---|---|---|
| No INSERT policy | RLS is on and the table's policy list has nothing for INSERT (or ALL) | create policy … for insert to authenticated with check (auth.uid() = user_id) |
| auth.uid() mismatch or null | The request carries only the anon key with no signed-in session, or the client sends a user_id that is not the caller's | Sign the user in before the insert; set the column default to auth.uid() and stop sending user_id from the client |
| Missing or wrong WITH CHECK | A FOR ALL policy with only USING, or a check on a column the insert does not set | Write an explicit FOR INSERT policy whose WITH CHECK tests the ownership column |
| Anon role, or a SELECT policy missing behind .select() or upsert | Policy is scoped to authenticated but the user is logged out; or .insert() works and .insert().select() fails | Scope the policy to the role that actually inserts; add SELECT (and UPDATE for upsert) policies |
Which AI builders ship Supabase RLS blocking insert?
How often each AI builder ships this error and the pattern that produces it.
| Builder | Frequency | Pattern |
|---|---|---|
| Lovable | Every Supabase scaffold | RLS enabled with no policy for one of the operations the app uses |
| Bolt.new | Common | FOR ALL policy with USING only, reused as the insert check |
| Base44 | Common | FOR ALL WITH CHECK (true) — identical to no protection |
| Cursor | Sometimes | Leaves user_id nullable with no default auth.uid() |
| Replit Agent | Rare | Targets policies at `public` role — includes anon |
Related errors we fix
How do I stop Supabase RLS blocking insert recurring?
- →Never use service_role in preview — test with anon + authenticated so the model gets RLS feedback.
- →Always set the ownership column default to `auth.uid()`.
- →Pair every INSERT policy with a matching SELECT policy for the same role.
- →Ship a pgTAP test suite asserting cross-tenant writes fail with 42501.
- →Scope policies to `authenticated`, never `public` — `public` includes anon.
- →Use the dashboard RLS Tester (feature preview, April 2026) to run a query as an impersonated user and see which policies get evaluated — but it only supports `SELECT` for now, so INSERT policies still need a real authenticated session or a pgTAP test.
Still stuck with Supabase RLS blocking insert?
Supabase RLS blocking insert questions
What does Postgres error 42501 mean on an INSERT?+
Why does my INSERT return PGRST116 instead of 42501?+
Does enabling RLS without policies block all inserts?+
What is the difference between USING and WITH CHECK in an INSERT policy?+
How do I write an insert policy in Supabase?+
Is it safe to disable RLS?+
Should I use the service role key to bypass RLS?+
How long does a full Supabase RLS audit take?+
Ship the fix. Keep the fix.
Emergency Triage restores service in 48 hours. Break the Fix Loop rebuilds CI so this error cannot ship again.
Hyder Shah leads Afterbuild Labs, shipping production rescues for apps built in Lovable, Bolt.new, Cursor, Replit, v0, and Base44. our rescue methodology.