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 badges2 Answers
Reset to default 7According 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
本文标签:
版权声明:本文标题:javascript - How to use the signUp() method in Supabase to add additional user info when signing up - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.roclinux.cn/p/1744067405a2527859.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论