Home > database >  How to use the signUp() method in Supabase to add additional user info when signing up
How to use the signUp() method in Supabase to add additional user info when signing up

Time:02-03

I am attempting to build a Vue.js application that includes authentication with Supabase. I wish to use the built-in Supabase signUp() method to handle additional user data when signing up. To do this, I added a property to the signUp object that stores additional user data, along with the email and password:

let { data, error } = await supabase.auth.signUp({
  email: '[email protected]',
  password: 'QQlbOIyZuwutISUzceOz',
  data: { isVendor: true }
})

However, when I run console.log after creating the user, I do not see an additional data property added to the user object.

I also tried assigning data to the existing user_metadata property in the user object, like so:

let { data, error } = await supabase.auth.signUp({
  email: '[email protected]',
  password: 'QQlbOIyZuwutISUzceOz',
  user_metadata: { isVendor: true }
})

However, this also did not work. How can I configure the signUp() method (or possibly the registered user portal in my Supabase dashboard) to store additional user data?

CodePudding user response:

According to docs only way to add extra details while signup is to add in data like this :

const { data, error } = await supabase.auth.signUp(
  {
    email: '[email protected]',
    password: 'example-password',
    options: {
      data: {
        first_name: 'John',
        age: 27,
      }
    }
  }
)

These data will be added to a column named raw_user_meta_data as a json. if you want to persist this meta data ypu can write a trigger like below.

* This trigger automatically creates a user entry when a new user signs up via Supabase Auth.
*/ 
create function public.handle_new_user() 
returns trigger as $$
begin
  insert into public.mrbs_users (id, email, name)
  values (new.id, new.email, new.raw_user_meta_data->>'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();
  • Related