Skip to content
← All guides

Security

"permission denied for table" (42501) in Supabase after the grants change: why new tables stopped working

By Jan Lipmann, appienceChecked against sources on 8 min read

Supabase set 2026-10-30 as the date from which a new table in the public schema of an existing project is no longer reachable from your app until someone grants access to it. Tables that already existed keep working, which is why only the feature your AI tool just added shows an empty screen or a 42501 error. The fix is a few grant statements - written together with Row Level Security, not instead of it.

SupabasePostgreSQLLovable

What you are seeing

You asked your AI tool for a new feature - comments, bookings, a wishlist - and it created a new table for it. Everything else in the app still works. The new part does not:

  • The new screen shows an empty list, or a save button that does nothing, even though you can see rows in the Supabase Table Editor.
  • The browser console or your app logs show permission denied for table your_table with code 42501.
  • The request to /rest/v1/your_table comes back with status 401 when nobody is signed in, or 403 for a signed-in user - that is how Supabase's Data API maps error 42501 (PostgREST error codes).
  • It started after 2026-10-30 on an older project, or on a new table in a project created from 2026-05-30 onwards (the new default was rolled out gradually over a few weeks), or in any project created with "Automatically expose new tables" unchecked.

Why an empty screen and not an error message: supabase-js does not throw when a request fails, it returns a { data, error } pair (Handling errors in supabase-js). Code that only reads data and never looks at error simply renders nothing.

How to check it yourself

Run these on your own project only. All of them only read information - nothing is changed.

Note: The steps assume a Supabase project you can open in the Supabase dashboard. If your app runs on Lovable's built-in backend instead, the database is still PostgreSQL and grants work the same way, but where you run SQL is different - see Lovable's FAQ. This page does not cover whether or when the Supabase change applies there.

1. Read the full error, not just the empty screen

Open the app in Chrome, press F12 (Cmd+Option+I on a Mac), go to the Network tab, type rest/v1 in the filter box and reload the broken screen. Click the red request and open Response. A missing grant looks like this:

{
  "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;"
}
This is the response format from Supabase's changelog. The hint names the missing privilege and the role that lacked it: anon means a signed-out visitor, authenticated a signed-in user.

Code 42501 is Postgres's generic insufficient_privilege error (PostgreSQL error codes), so it has more than one cause. If the message says permission denied for table, read on. If it says new row violates row-level security policy for table instead, the grant is there and an RLS policy is blocking the insert or update - Supabase's 42501 troubleshooting article lists both cases, and the fix is a policy, not a grant.

2. See which tables your app can reach

In the Supabase dashboard open SQL Editor and run this. It lists every table and view in public, whether RLS is on, and what signed-out visitors (anon) and signed-in users (authenticated) are allowed to do with it:

select
  c.relname as table_name,
  c.relrowsecurity as rls_on,
  has_table_privilege('anon', c.oid, 'select') as anon_select,
  has_table_privilege('authenticated', c.oid, 'select') as user_select,
  has_table_privilege('authenticated', c.oid, 'insert') as user_insert,
  has_table_privilege('authenticated', c.oid, 'update') as user_update,
  has_table_privilege('authenticated', c.oid, 'delete') as user_delete
from pg_class c
join pg_namespace n on n.oid = c.relnamespace
where n.nspname = 'public'
  and c.relkind in ('r', 'p', 'v', 'm')
order by c.relname;
has_table_privilege is a built-in Postgres function (System information functions). rls_on only means something for tables; views show false there.
  • The new table shows false in every privilege column while your older tables show true: this is the grants change. The fix below applies.
  • The new table shows true for the operation that fails: the grant is not the problem. Look at the RLS policies and at the exact error message from step 1.
  • An older table shows rls_on = false and true in the privilege columns: that table is open to anyone with your public key. It is a separate, more urgent problem - see our guide on open Supabase tables.

3. Confirm what new tables get by default

This query is from Supabase's Securing your API guide. It shows which privileges are added automatically to new tables, sequences and functions that the postgres role creates in public:

select
  case d.defaclobjtype
    when 'r' then 'tables'
    when 'S' then 'sequences'
    when 'f' then 'functions'
  end as object_type,
  a.grantee::regrole as role,
  string_agg(a.privilege_type, ', ' order by a.privilege_type) as privileges
from pg_default_acl d
cross join lateral aclexplode(d.defaclacl) a
where d.defaclrole = 'postgres'::regrole
  and d.defaclnamespace = 'public'::regnamespace
  and a.grantee in ('anon'::regrole, 'authenticated'::regrole, 'service_role'::regrole)
group by 1, 2
order by 1, 2;
No rows for tables means every new table starts with no access for your app's roles. Every table your AI tool adds from now on needs explicit grants.

You can see the same thing in the dashboard: Supabase's changelog describes a Data API exposure badge in the Table Editor, and the Data API settings (Integrations > Data API) hold the "Automatically expose new tables" option. Supabase's knowledge base also has a query that lists the 42501 errors recorded in your project's Postgres logs (Database API 42501 errors).

Why it happens

Postgres checks two things before your app touches a table. Grants decide whether a role may use the table at all. Row Level Security (RLS) policies decide which rows it may see or change. A missing grant fails with 42501 before any policy is even looked at (Row Level Security).

Until 2026, Supabase handed out the grants for you: every new table in public automatically gave select, insert, update and delete to anon, authenticated and service_role. Supabase changed that default (changelog):

  • 2026-04-28: the option to turn the automatic grants off appeared on the project creation screen.
  • 2026-05-30: no automatic grants became the default for new projects, rolled out gradually over a few weeks.
  • 2026-10-30: the date set for applying the change to all existing projects.

The change only affects new objects. Tables that existed before keep their grants, which is why the old parts of your app keep working. It applies to the Data API - what supabase-js, the REST endpoint /rest/v1/ and GraphQL use. Direct Postgres connections (psql, an ORM, a server with a connection string) are not affected, and neither are tables in the auth, storage and realtime schemas.

Supabase's stated reason: AI agents, CLI scripts and platforms now create tables with no person reviewing the change, and automatic grants made a new table reachable before anyone had secured it. AI tools are also where the gap shows: a migration that runs create table and enable row level security but no grant produces exactly this error. Supabase's changelog asks people who use AI tools to update the tool's instructions so that grants are part of every new table.

How to fix it

Warning: Do not fix this by granting everything to everyone. Supabase documents a rollback that grants all privileges on all tables in public to anon and authenticated (changelog). On a table without RLS that makes every row readable and writable by anyone with your public key. Grant per table, and only together with RLS.

1. Decide who needs what, per table

  • Signed-out visitors (anon): usually nothing, or select only for content that is meant to be public, like a product catalogue.
  • Signed-in users (authenticated): only the operations the app really offers. If users never delete bookings, do not grant delete.
  • Server code with a secret key (service_role): Edge Functions or a backend that uses the secret key need their own grant too. That role bypasses RLS, so it must never be used in the browser.

2. Grant, enable RLS and add policies in one change

Example for a table where each row belongs to one user, with a user_id uuid column. This follows the steps in Supabase's Securing your API and Row Level Security docs. Replace public.notes with your table:

-- 1. Row Level Security first, so the grants never expose unfiltered rows
alter table public.notes enable row level security;

-- 2. Only the privileges the app needs
grant select, insert, update, delete on table public.notes to authenticated;
grant select, insert, update, delete on table public.notes to service_role;

-- 3. Policies: each user sees and changes only their own rows
create policy "Owners can read their notes"
on public.notes for select
to authenticated
using ( (select auth.uid()) = user_id );

create policy "Owners can create their notes"
on public.notes for insert
to authenticated
with check ( (select auth.uid()) = user_id );

create policy "Owners can update their notes"
on public.notes for update
to authenticated
using ( (select auth.uid()) = user_id )
with check ( (select auth.uid()) = user_id );

create policy "Owners can delete their notes"
on public.notes for delete
to authenticated
using ( (select auth.uid()) = user_id );
To see the policies a table already has, run select policyname, cmd from pg_policies where schemaname = 'public' and tablename = 'notes'; and skip the create policy statements you already have.

For a table that everyone may read but nobody edits from the app, such as announcements filled by an admin or a backend job, grant select only to the app's roles, and give write access only to service_role if a backend job fills it through the Data API:

alter table public.announcements enable row level security;
grant select on table public.announcements to anon, authenticated;
grant select, insert, update, delete on table public.announcements to service_role;

create policy "Anyone can read announcements"
on public.announcements for select
to anon, authenticated
using ( true );

Two details that trip people up:

  • Number columns filled by a sequence (serial, bigserial): the sequence is a separate object, and getting the next value requires usage or update on it (PostgreSQL sequence functions). If inserts fail with permission denied for sequence notes_id_seq, grant it: grant usage on sequence public.notes_id_seq to authenticated;. Columns created as generated ... as identity or with a uuid default do not need this.
  • Views: a view needs its own grant (otherwise the error reads permission denied for view), so grant select on public.your_view to authenticated; as well. Create it with (security_invoker = on) so it respects the RLS of the tables underneath (Row Level Security).

3. Make it stick in your migrations

If your project keeps migrations in a supabase/migrations folder, put the statements above into the migration that creates the table, not only into the SQL Editor - otherwise the next environment, branch or rebuild gets the table without grants again. Supabase's guidance is to bundle the grants with enable row level security and the policies in the same migration. Then add a standing instruction to your AI tool, for example:

Whenever you create a table in the public schema of Supabase, in the same
migration: enable row level security, grant only the privileges each role
needs (anon, authenticated, service_role) on that table, and create one RLS
policy per operation. Never grant on all tables in schema public.

4. Verify

Run the table query from step 2 of the check again: the new table should now show true only where you granted it, and rls_on = true. Reload the app and use the feature as a signed-in test user, then sign out and check that signed-out visitors cannot see what they should not. To test what a stranger can read with your public key, use the curl test from our open-tables guide.

Grants are documented in full in the PostgreSQL GRANT reference. Changing what future tables get automatically is done with ALTER DEFAULT PRIVILEGES, but per-table grants in your migrations are easier to review and are what Supabase now recommends.

When to get help

A single new table with one owner per row is a ten-minute fix. Get a second pair of eyes when:

  • The check turned up older tables with RLS off and full grants - your app has been open longer than it has been broken.
  • Several tables broke at once and you are not sure which should be public, which private and which server-only.
  • Data is shared between users - teams, organisations, invitations - so a simple auth.uid() = user_id policy does not fit.
  • The app is live with paying users and you need the fix right the first time, in a migration, without guessing.

Sources

Primary documentation this guide was checked against. Platforms change - if something here no longer matches, the source wins.

Frequently asked questions

Is "permission denied for table" a security problem?
No - it is the database refusing access, which is the safe direction. The risk is in the fix: granting access to a table that has no Row Level Security, or granting to every table at once, can expose data that was private.
Why do my old tables still work and only the new one fails?
Supabase's change only affects tables created after it reached your project (2026-10-30 for existing projects). Existing tables kept the grants they had, so they stay reachable. Every new table needs explicit grants.
Can I just run the GRANT from the error's hint?
Only after you have checked that the table has RLS enabled and policies that fit. The hint names the privilege that was missing for one role and one request. It says nothing about which rows that role should see - that is what the policies are for.
Why do I get 401 for signed-out users and 403 for signed-in users?
Supabase's Data API returns error 42501 as HTTP 403 when the request carries a signed-in user's token and as 401 otherwise. Both mean the same thing: the role has no privilege on that table.
Does this affect my mobile app?
If the app talks to Supabase through supabase-js or another Supabase client library, yes - those use the Data API. If your backend connects to Postgres directly with a connection string, the change does not apply to those queries.
My error says 42501 but mentions row-level security. Is that the same problem?
No. Postgres uses 42501 for several permission problems. When the message reads new row violates row-level security policy, the grant is in place and an RLS policy rejected the insert or update. Fix the policy's with check condition, not the grants.

Related guides

Fixed-price audit

Want someone to check the whole app, not just this?

A review of data security, production readiness and App Store readiness for apps built with AI tools. 900 USD, a ranked list of fixes within 5 business days.