Mendlark / Guides

Supabase "permission denied for table" (42501) on a new table: how to fix it

You (or Lovable, Bolt or Cursor) created a new table, turned on row level security, wrote policies, and the app still fails with permission denied for table your_table, error code 42501, often shown as a 401 or 403. Old tables keep working. Only the new one is broken. This is Supabase's grants change, and the fix takes one migration.

Stuck on this? Get it fixed for €49.

Fixed in 48 hours or you don't pay. Launch deal for the first 5 customers (normally €79). You get the tested fix as a pull request, so nothing changes until you merge it.

Get it fixed for €49

What changed

Until now, every new table in the public schema was automatically granted select, insert, update and delete for the anon, authenticated and service_role roles, so row level security was the only gate. New Supabase projects stopped doing that from 30 May 2026, and on 30 October 2026 Supabase applies it to all existing projects too (Supabase's announcement).

After that, a new table needs an explicit Postgres grant before the Data API can see it. That's the REST and GraphQL layer that supabase-js calls, which is how almost every Lovable and Bolt app talks to its database.

  • Tables you already have keep their grants and keep working.
  • Apps that connect straight to Postgres (an ORM or a connection string on a server) aren't affected.
  • RLS works exactly as before. It just runs second now.

What it looks like

{
  "code": "42501",
  "message": "permission denied for table your_table",
  "hint": "Grant the required privileges to the current role with: GRANT SELECT ON public.your_table TO anon;"
}

Postgres checks grants first and RLS second. If the grant is missing, your policies never even run, which is why "but I have policies" doesn't fix it.

1. Check what the table has

In the Supabase SQL editor:

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

If authenticated isn't in the list, signed-in users can't touch the table through the API.

2. Add only the grants you need, with RLS still on

alter table public.your_table enable row level security;

-- signed-in users: the operations your app actually uses
grant select, insert, update, delete on table public.your_table to authenticated;

-- server code and Edge Functions using the service_role key
grant select, insert, update, delete on table public.your_table to service_role;

-- only if signed-out visitors should read this table
-- grant select on table public.your_table to anon;

Leave anon out unless the table is meant to be public, like a list of blog posts. A profiles, orders or invoices table should never get anon access.

The error's hint suggests a grant. Read it rather than pasting it blindly: it names the role that failed, and that role may not be one that should have access.

3. Don't "fix" it the dangerous way

Two shortcuts make the error go away and open your data to anyone with your public anon key:

  • Turning off RLS. The grant is what's missing, not the policy. With RLS off and a grant in place, every row is readable by anyone.
  • grant all on all tables in schema public. This also hands access to tables where RLS was never turned on.

If an AI tool suggests either one, say no.

4. If inserts fail with "permission denied for sequence"

Tables with an auto-incrementing serial id use a sequence, and inserting needs permission on it too:

grant usage, select on sequence public.your_table_id_seq to authenticated;

Tables that use uuid ids with gen_random_uuid() don't need this.

5. Tell your AI builder to include grants every time

Lovable, Bolt and Cursor learned the old default: create the table, enable RLS, add policies, done. After 30 October that produces a table nobody can reach. Paste this into Lovable's Knowledge or project instructions, or your Cursor rules:

When you create a Supabase table in the public schema, put all of this in the same migration:
1. create table
2. alter table ... enable row level security
3. create policy for each operation the app needs
4. grant select, insert, update, delete on the table to authenticated
5. grant select, insert, update, delete on the table to service_role
6. grant select to anon only if signed-out users must read it
Never use grant all, and never turn off RLS to fix a permission error.

6. Test it like a real user

Sign in with a normal test account in a private window and try every action that touches the new table: create, view, edit and delete. Then sign out and make sure the private data is gone. Our Lovable launch checklist covers the rest of the go-live checks.

Quick checklist

  • New tables get explicit grants in the same migration as RLS and policies
  • authenticated and service_role get only the operations the app uses
  • anon gets nothing unless the table is public
  • RLS stays on, and no grant all
  • Sequence grants added for serial ids
  • Tested signed in and signed out after the change

Want a second pair of eyes?

Mendlark fixes AI-built apps that break at go-live. Start with a free scan and we'll tell you what's wrong and what a fix costs, or get a fix for €49 (launch price, normally €79) and we'll fix it, test it and send it as a pull request. Related: Supabase view bypasses RLS.

Not sure what else is wrong? Paste your app link into the free instant check and get a plain-English list of problems in seconds.