SupabaseS
Supabase4y ago
Zeph

Trigger Function

I currently have this trigger and function to add a new row to my public users table whenever a new user signs up.
How do I also trigger a function that adds a row in the folder table with the name set to 'default' and the userId set to the new user that was just created?
My folder table has the following columns: id, name, userId

Thank you!

create or replace function public.handle_new_user() 
returns trigger as $$
begin
  insert into public.users (id, email)
  values (new.id, new.email);
  return new;
end;
$$ language plpgsql security definer;

drop trigger if exists on_auth_user_created on auth.users;
create trigger on_auth_user_created
  after insert on auth.users
  for each row execute procedure public.handle_new_user()
Was this page helpful?