You create a new table, add RLS policies that look perfect, and your API calls fail with:
error code 42501: permission denied for table profiles
Your RLS policies might be perfectly fine. The problem could be one layer below RLS: PostgreSQL privileges.
Supabase's recent default change makes this especially important. Here's what changed, the SQL that fixes it, and a two-user test to check that your policies still hold.
What changed
Supabase no longer automatically grants the API roles (anon, authenticated, and service_role) access to newly created tables in the public schema by default.
Here's the timeline:
April 28, 2026: Supabase introduced the option to create projects without automatically exposing new tables.
May 30, 2026: The new behavior began rolling out as the default for new projects.
October 30, 2026: The change was applied to existing projects.
Once this change reaches your project, newly created tables in the public schema require explicit grants before the Data API can access them.
Existing tables keep their current grants. The change affects newly created tables, not existing table permissions.
This applies to the Supabase Data API, including requests made through supabase-js, REST, and GraphQL. Direct PostgreSQL connections are not affected.
Read the official announcement: Supabase changelog: Tables not exposed to Data API automatically.
The important thing to understand is that there are two separate layers:
Grants decide whether a database role can access a table or perform an operation.
RLS policies decide which rows that role can see or modify.
You need both.
A policy without the required grant cannot provide access. A grant without appropriate RLS policies can expose rows to roles that shouldn't see them.
The fix
Grant only what each role needs, and nothing more.
For this example, let's assume users can read their own profile and update only their full_name and avatar_url.
First, remove existing table privileges from the API roles and PUBLIC:
revoke all on table public.profiles
from PUBLIC, anon, authenticated, service_role;
Then grant the required permissions:
-- Logged-in users can read profiles.
grant select on table public.profiles
to authenticated;
-- Logged-in users can update only these columns.
grant update (full_name, avatar_url)
on table public.profiles
to authenticated;
-- Server-side service role gets the required table access.
grant select, insert, update, delete
on table public.profiles
to service_role;
Notice what's missing:
anon has no table privileges.
authenticated has no insert or delete permission.
Authenticated users cannot update every column.
That's intentional.
The column-level UPDATE grant matters because RLS restricts rows, not individual columns. Without column-level restrictions, a user might be able to modify sensitive fields on their own profile.
Add owner-only RLS policies
Enable RLS, then write policies so users can only access their own profile:
alter table public.profiles
enable row level security;
create policy "Users can view own profile"
on public.profiles
for select
to authenticated
using (auth.uid() = id);
create policy "Users can update own profile"
on public.profiles
for update
to authenticated
using (auth.uid() = id)
with check (auth.uid() = id);
The WITH CHECK on the update policy matters.
USING determines which existing rows can be targeted.
WITH CHECK validates the resulting row after the update.
Without the appropriate check, a user could potentially change their profile's id and attempt to associate it with another user's identity.
Create profiles with a trigger, not from the client
There is no INSERT policy above. Clients cannot create profile rows directly.
Instead, a database trigger creates the profile when a user signs up.
create or replace function public.handle_new_user()
returns trigger
language plpgsql
security definer
set search_path = ''
as $$
begin
insert into public.profiles (
id,
email,
full_name,
avatar_url
)
values (
new.id,
new.email,
new.raw_user_meta_data->>'full_name',
new.raw_user_meta_data->>'avatar_url'
);
return new;
end;
$$;
create trigger on_auth_user_created
after insert on auth.users
for each row
execute function public.handle_new_user();
Why use SECURITY DEFINER?
It runs the function with its owner's permissions, allowing the trigger to insert the profile even though authenticated users don't have direct INSERT permission.
Notice SET search_path = '' and the explicitly qualified public.profiles table name. This avoids relying on an implicit search path inside a privileged function.
Test it with two users
Don't trust a policy just because it looks right.
Create two test users, sign in as each, and try to access another user's profile.
Assume userA and userB are separate Supabase clients, each authenticated as the corresponding user.
// User B tries to read User A's profile.
const { data: read, error: readError } = await userB
.from('profiles')
.select('*')
.eq('id', userA.id);
// A real request error should not be mistaken for a successful test.
if (readError) {
throw readError;
}
if (read.length !== 0) {
throw new Error('FAIL: User B can read User A profile');
}
console.log('PASS: User B cannot read User A profile');
// User B tries to update User A's profile.
const { data: write, error: writeError } = await userB
.from('profiles')
.update({ full_name: 'hacked' })
.eq('id', userA.id)
.select();
if (writeError) {
throw writeError;
}
if (write.length !== 0) {
throw new Error('FAIL: User B can update User A profile');
}
console.log('PASS: User B cannot update User A profile');
Expected result:
Reading another user's profile returns an empty array.
Updating another user's profile affects zero rows and returns an empty array.
Actual request errors are reported separately rather than being mistaken for successful RLS checks.
If either operation returns User A's row, investigate your policies.
If User B cannot access their own profile either, check your grants, policies, and authentication setup.
These two checks are useful, but they don't prove every permission or policy in your application is correct. Test your own rows, allowed updates, protected columns, and anonymous access separately too.
Common mistakes
Granting access to anon just to make the error disappear. This can expose data if your RLS configuration is missing or too permissive.
Using USING (true) for authenticated users. That allows every authenticated user to access every matching row.
Forgetting WITH CHECK on UPDATE policies. Always validate the resulting row.
Giving users unrestricted UPDATE privileges. RLS controls rows, not columns. Use column-level grants when certain fields must remain protected.
Putting the service role key in client-side code. It bypasses RLS. Keep it on the server and restrict its use.
Want the setup already done?
I built an Express + Supabase starter that includes explicit grants, owner-only RLS, a signup trigger, and a two-user test that checks access between users.
It also includes additional authentication and server-side hardening.
Disclosure: I'm the author. It's a paid starter, not a security audit. The included RLS setup and test cover the profiles table. If you add your own tables, you'll need to write and test their policies and grants too.
https://shaameer.gumroad.com/l/SupabaseExpressjsProductionBackend
Either way, the SQL above is free to copy.
If it saved you some debugging time, share it with someone staring at a 42501 error. IF something doesnt work ask me and i will reply.

