Shipping an AI app or agent? Security review in 1 working day: $149 / ₹13,900. Request a review →
AI Review Ready
Home / Error fixes / Supabase 42501
Fix · Supabase

Supabase error 42501: permission denied

Read the message first. permission denied for table ... means the table has no GRANT for the anon or authenticated role. Supabase stopped exposing new tables to the Data API automatically in 2026, which hits tables that an AI tool, script or migration created. new row violates row-level security policy ... means the grant is fine but an RLS policy rejected the row. Never fix either one by turning RLS off.

Which message, which fix

MessageCauseFix
permission denied for table your_tableNo GRANT for the API roleFix 1
new row violates row-level security policy for table "your_table"An INSERT or UPDATE policy's check failed, or there is no policyFix 2
Same, but only when you're logged outThe request runs as anon, so auth.uid() is nullFix 3
403 Forbidden: new row violates row-level security policy on a Storage uploadMissing policy on storage.objectsFix 2 (Storage)
permission denied for schema ...The schema isn't exposed, or it's auth/vaultOther causes

In supabase-js the error comes back as { code: "42501", message, details, hint }. PostgREST returns it as HTTP 403 when the user is signed in and 401 when not.

Fix 1: grant the API roles access to the table

Supabase changed how new tables reach the Data API. Per its changelog: an opt-in from 28 April 2026, the default for new projects from 30 May 2026, and applied to all existing projects from 30 October 2026. New tables in public get no grants for anon or authenticated. Tables that already existed keep their grants. Supabase says you're affected if "an AI tool, CLI script, or Management API call creates tables and expects them to be API-accessible".

The error's hint tells you the missing grant. Grant only what the app needs:

-- signed-in users read and write
grant select, insert, update, delete on table public.your_table to authenticated;
-- only if logged-out visitors must read it
grant select on table public.your_table to anon;

Check what a table has now:

select grantee, privilege_type
from information_schema.role_table_grants
where table_name = 'your_table';

A grant only opens the door to RLS. Supabase: "A missing grant raises a 42501 error before any policy runs." After granting, make sure RLS is on and the table has policies (Fix 2), or the grant exposes every row.

To change the behaviour for future tables: Dashboard, Integrations, Data API settings, "Automatically expose new tables".

Fix 2: the RLS policy rejected the row

An INSERT policy uses with check only. PostgreSQL: "An INSERT policy cannot have a USING expression." If the check returns false or null, the insert fails with 42501. The usual pattern, from Supabase's docs:

create policy "Users can create their own rows"
on public.your_table for insert
to authenticated
with check ( (select auth.uid()) = user_id );
  • The client must send the matching value. If the insert doesn't include user_id, or sends another user's ID, the check fails.
  • RLS on, no policy at all: PostgreSQL assumes "default deny". Selects come back empty (no error); inserts fail with 42501.
  • .insert().select(), upsert and upsert: true also need a SELECT policy. PostgreSQL: "If a newly inserted or updated row does not satisfy the relation's SELECT policies, an error will be thrown."
  • UPDATE needs a SELECT policy too. Supabase: "Without a SELECT policy, the UPDATE operation will not work as expected."
  • Storage uploads: add an INSERT policy on storage.objects, and when you use upsert: true, a SELECT policy that mirrors it (Supabase KB).

Fix 3: the user isn't signed in

Supabase: "auth.uid() returns null for any request whose JWT has no sub claim", and a request from a user who isn't signed in runs as anon. A policy comparing auth.uid() to a column can then never pass.

  • Sign the user in before the write, and check the session exists in the client.
  • Scope the policy to authenticated. Supabase: "Adding to authenticated keeps anon requests out".
  • Don't add or auth.uid() is null to make the error go away. Supabase warns against it: it opens the table to everyone.

Don't fix 42501 by disabling RLS

Turning RLS off makes the error disappear and makes the table public. Supabase's advisor flags that as RLS Disabled in Public (lint 0013, level ERROR): "anyone with the project's URL can CREATE/READ/UPDATE/DELETE (CRUD) rows", a "critically unsafe configuration". Its fix:

alter table public.your_table enable row level security;

then add policies. The advisor only fires when anon or authenticated has SELECT on the table, so a brand-new table with no grants won't trigger it, but it will the moment you grant access.

Other causes

  • Querying auth or vault from the client. Supabase: "API roles cannot access certain schemas, most notably auth and vault." Use a view or function in your own schema.
  • A custom schema that isn't exposed in the Data API settings.
  • Column-level grants with select *: select only the granted columns.

Running Claude Code, Codex or Cursor on real repos, or shipping an AI agent? A Quick Review ($149 / ₹13,900, 1 working day) checks one repo, config or setup for leaked keys, risky agent permissions and MCP servers. Request a Quick Review

FAQ

What does Supabase error 42501 mean?

It is PostgreSQL's insufficient_privilege error. In Supabase it means the request's role (anon or authenticated) has no GRANT on the table, or a row-level security policy rejected the row.

Why do new Supabase tables give permission denied in 2026?

Supabase stopped exposing new tables to the Data API automatically: default for new projects from 30 May 2026 and applied to existing projects from 30 October 2026. New public tables need an explicit GRANT to anon or authenticated.

How do I fix new row violates row-level security policy?

Add or fix the table's INSERT policy WITH CHECK clause, make sure the client sends the column the policy checks (such as user_id = auth.uid()), and add a SELECT policy if you insert with .select() or upsert.

Should I disable RLS to fix 42501?

No. Without RLS, anyone with your project URL can read and change every row. Supabase's advisor flags it as a critical error. Grant the role access and write policies instead.

Related errors

Sources

Read 2 Dec 2026. These tools change often: if a step no longer matches, the linked page wins.

Related free tools