should I also add an email in my function that han...
# sql
s
should I also add an email in my function that handles creating a new id in the 'profiles' table each time a new user appears in the auth table?
s
Yes
s
Thanks! How would that work? Something like this:
Copy code
begin
  insert into public.profiles (id,email)
  values (new.id, new.email);
  return new;
end;
s
Yep this is how I do it in my code. The only thing to look out for is that if a user should update their email in the
auth.users
table this won't update your
public.profiles
table, so you will need a
after update
trigger to update this.
s
Nice! Thanks!
Is this how that trigger should look like?
s
Yes except you don't want tit to trigger the handle_new_user function if its for the update, you will need to create a new function for the update
s
Oh, okay, yeah that makes sense. Would the function look similar? Sorry, this is where it's getting fuzzy 😅