Supabase "permission denied for table" on a new table: add the missing GRANT
By AI App Medic · Updated · Supabase · Grants · Lovable · Security
You asked Lovable, Bolt or Cursor for a new feature. It created a table, wired up the query, and the page shows nothing. The browser console or the Supabase response has this:
{
"code": "42501",
"message": "permission denied for table invoices",
"hint": "Grant the required privileges to the current role with: GRANT SELECT ON public.invoices TO authenticated;"
}
Every table you made a few weeks ago still works. Only the new ones fail. Nothing is wrong with your code or your RLS policies. The table simply has no grant for the role that is calling it.
Why this started happening
Postgres checks two separate things before it returns a row. First, does this role have a privilege on the table at all (a GRANT)? Second, which rows does row level security let it see? Supabase used to handle the first part for you: every new table in the public schema got select, insert, update and delete granted to anon, authenticated and service_role automatically.
That default is gone. Supabase changed it for new projects from May 30, 2026, and applied it to all existing projects on October 30, 2026. Existing tables kept their grants. Any table created after the change, whether through the SQL Editor, a migration, the CLI or an AI tool, is unreachable from supabase-js until someone grants it. Because the grant check happens before RLS, a perfect set of policies does not help.
If you only connect over a direct Postgres connection (an ORM on a server with a connection string), you are not affected. This is about the Data API, which is what the Supabase client libraries call.
Step 1: make sure it is the grant, not RLS
Three errors look similar in a hurry. Read the message, not just the code:
permission denied for table invoiceswith aGRANThint: missing grant. This guide.new row violates row-level security policy for table "invoices": the grant exists, but no INSERT policy allowed the row. See new row violates row-level security policy.- No error, just
[]: the grant exists and RLS filtered every row. See Lovable + Supabase RLS not working.
The hint names the role and the privilege. If it says TO anon while you expected a signed-in user, the request went out before the session loaded, which is a separate bug worth fixing too.
Step 2: see what the table has right now
Run this in the SQL Editor, with your table name:
select grantee, privilege_type
from information_schema.role_table_grants
where table_schema = 'public'
and table_name = 'invoices'
order by grantee, privilege_type;
On a table created after the change you will usually see only postgres rows. Compare it with an older table that works and the difference is obvious. You can also check a single privilege:
select has_table_privilege('authenticated', 'public.invoices', 'select');
Step 3: grant per role, then lock it down with RLS
Treat the grant, RLS and policies as one unit in one migration. For a typical table where each user owns their own rows:
-- 1. Who can reach the table
grant select, insert, update, delete on table public.invoices to authenticated;
grant select, insert, update, delete on table public.invoices to service_role;
-- Only if signed-out visitors must read it:
-- grant select on table public.invoices to anon;
-- 2. Turn on row level security
alter table public.invoices enable row level security;
-- 3. Which rows each user can touch
create policy "own invoices: read"
on public.invoices for select to authenticated
using ((select auth.uid()) = user_id);
create policy "own invoices: insert"
on public.invoices for insert to authenticated
with check ((select auth.uid()) = user_id);
create policy "own invoices: update"
on public.invoices for update to authenticated
using ((select auth.uid()) = user_id)
with check ((select auth.uid()) = user_id);
create policy "own invoices: delete"
on public.invoices for delete to authenticated
using ((select auth.uid()) = user_id);
A few details that catch people:
- Do not grant to
anonby reflex. Most app tables have no business being read by signed-out visitors. Grantanononly for content that is genuinely public, like a list of published posts, and give itselectonly. service_roleneeds a grant too. It skips RLS, but it does not skip grants. If an Edge Function or a webhook handler that uses the secret key gets the same error, this is why.serialid columns need the sequence. If an insert fails withpermission denied for sequence invoices_id_seq, addgrant usage, select on sequence public.invoices_id_seq to authenticated;. Columns declaredgenerated always as identityor uuid defaults do not need this.- Views are separate objects. A view needs its own
grant select. Create it withwith (security_invoker = true)so the RLS on the underlying table still applies to the caller. - RPC functions. If
supabase.rpc()fails withpermission denied for function, grantexecuteon that function to the role that calls it, and nothing wider.
Grants take effect immediately. Reload the page and the query should return data, or an empty array if your policies do not match any rows yet.
Do not fix it with a bulk grant
The quickest thing that "works" is grant all on all tables in schema public to anon, authenticated. Supabase documents a bulk grant as a rollback path, but as a fix it undoes the point of the change. Every table in public becomes reachable again, including audit logs, admin tables and anything created with RLS off. In AI-built apps that last group is common, because a table created from the SQL Editor or by a migration does not always have RLS turned on. If you already ran a bulk grant, list the tables that have grants but no RLS:
select c.relname as table_name
from pg_class c
join pg_namespace n on n.oid = c.relnamespace
where n.nspname = 'public'
and c.relkind = 'r'
and not c.relrowsecurity
and has_table_privilege('anon', c.oid, 'select');
Any row in that result is readable by anyone who has your public anon key, which ships in your front end. Either enable RLS with policies or revoke: revoke all on table public.table_name from anon, authenticated;. The RLS enabled but data still public guide covers the policy side of that audit.
A different error that looks related
Could not find the table 'public.invoices' in the schema cache (code PGRST205) is not a grant problem. The API has not picked up the new table yet, or the name or schema is wrong. Check the spelling, then run notify pgrst, 'reload schema'; in the SQL Editor.
Prevention
Keep a migration template with the three blocks above and copy it for every new table. If an AI tool writes your migrations, tell it in the project instructions: every new table in public gets explicit grants for the roles that need them, RLS enabled and one policy per operation, in the same migration. Check the Security Advisor and the Data API exposure badge in the Table Editor after each schema change. And test every new feature while signed in as a normal user and while signed out, since a table that only works for you in the dashboard has not been tested.
FAQ
Why do my old tables work but the new one fails?
Supabase used to grant select, insert, update and delete on every new table in the public schema to anon, authenticated and service_role. That default was removed for new projects from May 30, 2026 and for existing projects on October 30, 2026. Tables that already existed kept their grants. Tables created after the change get none until you add them.
Is it safe to just run grant on all tables in schema public?
Not as a fix. It re-exposes every table in public, including ones that were meant to stay private or have RLS turned off. Grant per table and per role, and check RLS on each table you grant.
Does service_role need a grant too?
Yes. The service role bypasses RLS but it does not bypass grants. If an Edge Function or a server route uses the secret key and gets permission denied, grant that table to service_role.
I added the grant and now I get an empty array. Is it broken?
No, that is RLS doing its job with no matching policy. The grant lets the role reach the table, and the policy decides which rows it sees. Add a select policy for the rows the user should read.
Related guides
- Fix “new row violates row-level security policy” (Supabase error 42501)
- Lovable + Supabase RLS not working: why your data is empty (and how to fix it)
- RLS is enabled but your Supabase data is still public: how to audit your policies
- Supabase Realtime not working: the channel says SUBSCRIBED but no changes arrive
- Supabase "Could not find the table in the schema cache": PGRST205 and PGRST204 explained