© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
SupabaseS
Supabase•4y ago•
10 replies
Connor

Error Inviting User After RLS Policy Query

I'm trying to add user management to a local Supabase instance and I'm running into an error relating to RLS policies.

With a blank database, if I run the following from the SQL editor, it executes without error.

create table public.profile (
  profile_id uuid references auth.users not null primary key,
  first_name text,
  last_name text,
  created_at timestamp with time zone default now(),
  updated_at timestamp with time zone
);

alter table public.profile
  enable row level security;

create policy "Users can select their own profile." on public.profile
  for select using (auth.uid() = profile_id);

create policy "Users can insert their own profile." on public.profile
  for insert with check (auth.uid() = profile_id);

create policy "Users can update own profile." on public.profile
  for update using (auth.uid() = profile_id);

create function public.handle_new_user()
returns trigger as $$
begin
  insert into public.profile (profile_id, first_name, last_name)
  values (new.id, new.raw_user_meta_data->>'first_name', new.raw_user_meta_data->>'last_name');
  return new;
end;
$$ language plpgsql security definer;
create trigger on_auth_user_created
  after insert on auth.users
  for each row execute procedure public.handle_new_user();
create table public.profile (
  profile_id uuid references auth.users not null primary key,
  first_name text,
  last_name text,
  created_at timestamp with time zone default now(),
  updated_at timestamp with time zone
);

alter table public.profile
  enable row level security;

create policy "Users can select their own profile." on public.profile
  for select using (auth.uid() = profile_id);

create policy "Users can insert their own profile." on public.profile
  for insert with check (auth.uid() = profile_id);

create policy "Users can update own profile." on public.profile
  for update using (auth.uid() = profile_id);

create function public.handle_new_user()
returns trigger as $$
begin
  insert into public.profile (profile_id, first_name, last_name)
  values (new.id, new.raw_user_meta_data->>'first_name', new.raw_user_meta_data->>'last_name');
  return new;
end;
$$ language plpgsql security definer;
create trigger on_auth_user_created
  after insert on auth.users
  for each row execute procedure public.handle_new_user();


But if I then try to invite a user via the Supabase dashboard, I get this error:

Failed to invite user: Database error finding user
Failed to invite user: Database error finding user


However, in the above if I change:

create policy "Users can select their own profile." on public.profile
  for select using (auth.uid() = profile_id);
create policy "Users can select their own profile." on public.profile
  for select using (auth.uid() = profile_id);

to

create policy "Users can select their own profile." on public.profile
  for select using (true);
create policy "Users can select their own profile." on public.profile
  for select using (true);

It allows me to invite users without error?

Thanks for any help!
Supabase banner
SupabaseJoin
Supabase gives you the tools, documentation, and community that makes managing databases, authentication, and backend infrastructure a lot less overwhelming.
45,816Members
Resources
Was this page helpful?

Similar Threads

Recent Announcements

Similar Threads

RLS Policy Syntax Error
SupabaseSSupabase / help-and-questions
3y ago
TUS error: RLS policy
SupabaseSSupabase / help-and-questions
3y ago
RLS Policy
SupabaseSSupabase / help-and-questions
4mo ago
Restrictive RLS policy
SupabaseSSupabase / help-and-questions
2mo ago