Hi! New to supabase here, how can I add more colum...
# javascript
y
Hi! New to supabase here, how can I add more columns to my users table? I'd like to store more than just email and phone number on a user. Things like their name and other preferences. I also can't seem to reference any ID's on the user table from another table I made, as a foreign key. Is this possible? or will I still need to create me own table of users and track this information there?
s
You can create a public users table, and then execute the following SQL to 'link' them - i.e. when a new user registers, their details will be propagated to your public users table:
Copy code
sql
CREATE FUNCTION public.handle_new_user()
RETURNS trigger AS $BODY$
begin
  insert into public.users (id, email, phone)
  values (new.id, new.email, new.phone);
  return new;
end;
$BODY$;
CREATE TRIGGER on_auth_user_created
    AFTER INSERT
    ON auth.users
    FOR EACH ROW
    EXECUTE FUNCTION public.handle_new_user();
As long as your public users table has the
id
,
email
and
phone
columns, you'll also be able to add any additional columns you need
y
Awesome, thanks!
@User this is actually returning a 500 for me. Any idea what might be going wrong? I used the user management starter to create my public users table but can't seem to get this trigger to insert. I added the language to it but that wasn't it
Turned out to be a permissions issue. had to add "SECURITY DEFINER" to the function