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();


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


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);

to

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!
Was this page helpful?