DB Function to Insert New Users

Hello,

I would like my DB Function to make a new record in public.userProfiles when a user is added to auth.users

Here is my function and the trigger that calls it. What am I doing wrong? I've never used Postgres or SQL
create or replace function public.handle_new_user() 
returns trigger as $$
begin
  insert into public.profiles (id, email)
  values (new.id->>id, new.email->>'email');
  return new;
end;
$$ language plpgsql security definer;


and the trigger:
create trigger on_auth_user_created
  after insert on auth.users
  for each row execute procedure public.handle_new_user();

I'm using this so that my security rules have a record to check UID against
Was this page helpful?