Supabase database

Lovable app broke on a new table? “Permission denied” (42501) and the fix that keeps it private

Since 30 October 2026, a table you or your AI builder adds to an existing Supabase project is invisible to the app until someone grants access. The app calls it and gets 42501 permission denied for table. Three quick fixes make the error go away. In our lab, all three made the data readable by anyone. Here is what happens, a read-only check, and the fix that works without opening anything.

TL;DR

  • From 30 Oct 2026, new tables in public get no grants for anon or authenticated on existing Supabase projects (Supabase changelog). Old tables keep working.
  • Granting to anon on a table with RLS off, as the error hint suggests, let a logged-out visitor read every row in our lab.
  • grant all on all tables in schema public also opened a table that had been locked on purpose, and let a visitor delete every row.
  • Putting the old default back reopens every table you create later.
  • The fix: RLS on, a grant for only what the screen needs, and a policy. Read-only check below.

What changed on 30 October

Supabase used to grant select, insert, update and delete on every new table in the public schema to the anon and authenticated roles, the roles your app uses through supabase-js. Any table appeared in the app the moment it was created, protected or not.

That changed in steps: optional from 28 April, the default for new projects from 30 May, and applied to all existing projects on 30 October 2026. Now a new table needs an explicit grant before the app can see it. Supabase says existing tables “keep their current grants and stay reachable”, so only tables created after the switch are affected. Their reason is the one this site is built around: agents and AI builders create tables without a human reviewing them, and the old default exposed tables nobody had protected.

So if your Lovable, Bolt or Grok Build app was fine until you added a feature last week, and that feature’s screen now fails, this is the likely cause.

Is this your error?

In the browser console or the network tab you’ll see a response like this one from our lab (PostgREST 12.2.12, the server behind Supabase’s Data API):

lab output, 2 Dec 2026
anon POST /leads: {"code":"42501","details":null,"hint":null,"message":"permission denied for table leads"} [HTTP 401]
anon GET  /leads: {"code":"42501","details":null,"hint":null,"message":"permission denied for table leads"} [HTTP 401]
old table still works, anon GET /profiles: [] [HTTP 200]

A signed-in user gets the same message with HTTP 403. On Supabase’s hosted Data API the response also carries a hint naming the missing grant, for example GRANT SELECT ON public.your_table TO anon; (Supabase’s example). The open-source PostgREST version we ran returns "hint": null, so your exact text may differ.

Not this error? A new row violates row-level security policy message is a different problem with its own guide: form submit RLS error. Empty results with no error usually mean RLS is on with no policy that matches the user.

The three quick fixes, tested

We rebuilt the situation on Postgres 17.11 and 18.6 with real PostgREST in front: an old profiles table (RLS on, owner-only), an admin_notes table the owner had locked so only the server could read it, then the post-30-October default, then a new contact-form table leads created with plain SQL, which is how AI builders usually write it (RLS isn’t turned on unless the SQL says so). Each fix was applied to a fresh copy. Results were the same on both Postgres versions.

Fix A: do what the hint says, on a table with RLS off

quick fix A (don’t)
grant select, insert on public.leads to anon;
lab output
anon POST /leads:  [HTTP 201]
anon GET  /leads: [{"name":"Carol","email":"carol@example.com","message":"call me on 07700 900123"},
                   {"name":"Dan","email":"dan@example.com","message":"hi"}] [HTTP 200]

The form works, and every message anyone ever sent can now be read by anyone with your public key, which ships in your site’s JavaScript. The hint is right about the missing grant. It can’t know your table has no RLS, and the grant alone gives a logged-out visitor every row.

Fix B: grant everything on every table

quick fix B (don’t)
grant all on all tables in schema public to anon, authenticated;
lab output
anon GET /leads: [{"email":"carol@example.com"}] [HTTP 200]
anon GET /admin_notes (table nobody asked about): [{"note":"refund for bob@example.com, card ending 4242"}] [HTTP 200]
anon DELETE /leads:  [HTTP 204]
rows left in leads: 0

This is the one to look out for in a chat with an AI builder, because it fixes every 42501 at once. It also undid a lock someone had put on admin_notes on purpose, and it gave a logged-out visitor delete: one request emptied the table. The profiles table stayed safe only because it had RLS on and an owner-only policy.

Fix C: put the old default back

quick fix C (don’t)
alter default privileges in schema public grant all on tables to anon, authenticated;
lab output
a table made a week later, anon GET /invoices: [{"customer_email":"erin@example.com","amount":1200}] [HTTP 200]

This doesn’t touch the broken table at all. It switches Supabase’s protection off for the future, so the next table the AI builder creates without RLS is public from its first second, exactly the case the 30 October change was made to stop.

Check your project (read-only)

Paste this into the Supabase SQL editor. It only reads the database’s own settings, not a single customer row, and changes nothing.

patchlabs-grants-check.sql (read-only)
-- Read-only. Run in the Supabase SQL editor.
-- 1. Which public tables can a logged-out visitor (anon) reach, and is RLS on?
select c.relname as table_name,
       c.relrowsecurity as rls_on,
       has_any_column_privilege('anon', c.oid, 'select') as anon_can_select,
       case
         when not (has_table_privilege('anon', c.oid, 'delete') or has_any_column_privilege('anon', c.oid, 'select,insert,update')) then 'not reachable by anon'
         when has_any_column_privilege('anon', c.oid, 'select') and not c.relrowsecurity then 'OPEN: anyone can read every row'
         when not c.relrowsecurity then 'OPEN: anyone can write'
         else 'RLS on: check its policies'
       end as verdict
from pg_class c join pg_namespace n on n.oid = c.relnamespace
where n.nspname = 'public' and c.relkind in ('r','p')
order by (case when c.relrowsecurity then 1 else 0 end), table_name;
-- 2. Will tables you create from now on be exposed to anon automatically?
select coalesce(string_agg(distinct x.privilege_type, ', '), 'none (the post-30-Oct default)') as anon_gets_on_new_tables
from pg_default_acl d join pg_namespace n on n.oid = d.defaclnamespace,
     lateral aclexplode(d.defaclacl) x
where n.nspname = 'public' and d.defaclobjtype = 'r' and x.grantee = 'anon'::regrole;

What the lab printed after fix B, then after fix C:

lab output, Postgres 17.11 and 18.6
-- after fix B
admin_notes | f | t | OPEN: anyone can read every row
leads       | f | t | OPEN: anyone can read every row
profiles    | t | t | RLS on: check its policies
none (the post-30-Oct default)
-- after fix C
invoices    | f | t | OPEN: anyone can read every row
...
DELETE, INSERT, MAINTAIN, REFERENCES, SELECT, TRIGGER, TRUNCATE, UPDATE

Any OPEN row needs fixing now. An RLS on row is only as safe as its policies; a policy of using (true) for anon still means every row (see RLS policies explained). If the second query prints anything other than “none”, someone has put the old default back.

The fix that keeps the data private

Supabase’s own advice is to treat three steps as one: grant, enable RLS, add policies. For a contact form, where visitors send a message and nobody should read messages back through the app, that is:

supabase/migrations/…_leads_access.sql
-- Contact form table: visitors may send a message, nobody can read them back through the API.
alter table public.leads enable row level security;
revoke all on public.leads from anon, authenticated;
grant insert (name, email, message) on public.leads to anon, authenticated;
create policy "anyone can send the form" on public.leads
  for insert to anon, authenticated
  with check (length(coalesce(message,'')) < 5000);
-- Read them in the Supabase dashboard, or from a server/Edge Function with the service role key.
grant select, insert, update, delete on public.leads to service_role;
lab output after the fix
anon POST /leads (form works):  [HTTP 201]
anon GET  /leads: {"code":"42501", ... "permission denied for table leads"} [HTTP 401]
signed-in stranger GET /leads: {"code":"42501", ... } [HTTP 403]
anon POST with return=representation (insert().select() in supabase-js): {"code":"42501", ...} [HTTP 401]

The last line matters. If the form’s code does .insert(...).select(), the app asks to read the row back, which needs a select grant. Remove .select() from the form’s insert rather than granting select to anon.

For a table each user owns (notes, orders, projects), grant to authenticated only and add an owner policy:

owner-only table
alter table public.notes enable row level security;
grant select, insert, update, delete on public.notes to authenticated;
create policy "own notes" on public.notes for all to authenticated
  using (user_id = (select auth.uid())) with check (user_id = (select auth.uid()));

Grant to anon only when logged-out visitors really need that table, and then only with RLS on. If you already ran fix B or C, undo them: revoke what anon doesn’t need table by table, and run alter default privileges in schema public revoke all on tables from anon, authenticated;.

Stop your AI builder doing it again

Paste something like this into your project’s instructions (Lovable’s Knowledge, a CLAUDE.md, or your rules file):

project instructions
Every new table in public: in the same migration, enable row level security, grant only the
privileges each role needs on that one table, and add policies. Never run "grant ... on all tables",
never change default privileges, never grant to anon on a table without RLS. If you see error 42501,
add the grant for that table only and tell me which role and privilege you added.

Supabase also publishes an agent skill that includes the grant step. Either way, look at the migration before you accept it: a line with on all tables or alter default privileges is the one to question.

Other reasons the connection breaks

  • Project paused. Free-plan projects can be paused after a period of inactivity; every request fails until you restore it in the dashboard. Nothing to grant.
  • Keys changed. If the project’s API keys were rotated, or the legacy keys were turned off after moving to the new publishable and secret keys, the app’s old key stops working. Update the key in the app’s settings. Never paste the service role or secret key into the frontend to make it work: that key skips RLS entirely (see is the anon key safe?).
  • Sign-up fails. “Database error saving new user” is a profile trigger problem: sign-up errors and the safe fix.
  • Uploads fail. Storage has its own policies and size limits: storage errors and the quota.

Sources and lab

The checks behind this guide, each with example code, a self-check and the fix.

Free check

Check your app for this, free.

Paste your public repo. PatchLabs rebuilds your database from its migrations, tests it as a visitor, a stranger and the owner, reads the code for keys and risky patterns, and hands you the fix.

First app free, fixes includedNever touches your database

Written by Manraj Singh Dhillon. Last checked 2 Dec 2026. Code samples are synthetic and run against your own project; nothing here names a real app. Spotted a mistake? Tell us.