admin 管理员组

文章数量: 1086019

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?

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?

Share Improve this question asked Feb 1, 2023 at 23:10 JS_is_awesome18JS_is_awesome18 1,7778 gold badges41 silver badges79 bronze badges
Add a ment  | 

2 Answers 2

Reset to default 7

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();

Had a similar issue with an additional user data that I want to put there and although the Vaysage solution works fine I've decided to have some more flexability by creating a new "users" table. Inside of this new "users" table you can put whatever data you want, later you can query it for something else by it's extra fields but with the normal (Supabase) I cannot see a way at this point.

So, after successfull signUp...

  const { data, error } = await supabase.auth.signUp({
    email: someEmail,
    password: somePassword,
  });

You can put your new user inside of the new "users" table from Supabase:

  if (data && data.user) {
    const { error: insertError } = await supabase
      .from("users")
      .insert([
        {
          user_id: data.user.id,
          email: data.user.email,
          username: "Some username !@#$%^&*()",
          firstName: "John",
          lastName: "Doe",
          age: "21",
          etc...
        },
      ]);

    if (insertError) {
      console.error(
        "Error inserting user into 'users' table:",
        insertError
      );
     }

   }

At the moment I find this to be working very well for me and I can quickly check the table inside Supabase and see straight away at a glance what extra data is existing and whats not for the registered users, but this is not the case with the Supabase Authentication at the moment.

Hope this was helpful!

Supabase I'm on => v2.31.0

本文标签:

Error[2]: Invalid argument supplied for foreach(), File: /www/wwwroot/roclinux.cn/tmp/view_template_quzhiwa_htm_read.htm, Line: 58
File: /www/wwwroot/roclinux.cn/tmp/route_read.php, Line: 205, include(/www/wwwroot/roclinux.cn/tmp/view_template_quzhiwa_htm_read.htm)
File: /www/wwwroot/roclinux.cn/tmp/index.inc.php, Line: 129, include(/www/wwwroot/roclinux.cn/tmp/route_read.php)
File: /www/wwwroot/roclinux.cn/index.php, Line: 29, include(/www/wwwroot/roclinux.cn/tmp/index.inc.php)