英文:
how to get userid from supabase default table react native
问题
在我的移动应用程序中,我有一个用户信息表,其中有一个主键,该主键引用了Supabase中的默认用户表,现在当尝试注册时,我无法插入到user_info表,因为我无法从auth.users中获取id。
如何获取用户ID以插入到user_info表中,以便它们可以关联?
const handlesignup = async () => {
try {
let { user, error } = await supabase.auth.signUp({
email: email,
password: password,
});
if (error) {
console.log('注册错误:', error.message);
return;
}
const { user1, error3 } = await supabase.auth.signInWithPassword({
email: email,
password: password,
});
if (error3) {
console.log('登录错误:', error3.message);
return;
}
const userId = user1?.id;
const { data, error: insertError } = await supabase
.from('user_info')
.insert([
{
name: name,
lname: lname,
id: userId,
},
]);
if (insertError) {
console.log('插入错误:', insertError.message);
return;
}
console.log('注册成功!');
console.log('用户ID:', userId);
} catch (error) {
console.log('错误:', error.message);
}
};
希望这可以帮助您将用户ID插入到user_info表中。
英文:
in my mobile app I have a userinfo table witch has a primary key that references the default user table in supabase now when trying to sign up i can insert into user_info because I cant get the id from auth.users
const handlesignup = async () => {
try {
let { user, error } = await supabase.auth.signUp({
email: email,
password: password,
});
if (error) {
console.log('Sign up error:', error.message);
return;
}
const {user1, error3 } = await supabase.auth.signInWithPassword({
email: email,
password: password,
});
if (error3) {
console.log('Sign in error:', error3.message);
return;
}
const userId = user1?.id;
const { data, error: insertError } = await supabase
.from('user_info')
.insert([
{
name: name,
lname: lname,
id: userId,
},
]);
if (insertError) {
console.log('Insert error:', insertError.message);
return;
}
console.log('Sign up successful!');
console.log('User ID:', userId);
} catch (error) {
console.log('Error:', error.message);
}
};
how do i get the userid to insert into the user_info table so they can be linked
答案1
得分: 0
我使用了从登录返回的数据,这是我访问它的方式。
const handlesignup = async () => {
try {
let { error } = await supabase.auth.signUp({
email: email,
password: password,
});
if (error) {
console.log('Sign up error:', error.message);
return;
}
const { data, error: error2 } = await supabase.auth.signInWithPassword({
email: email,
password: password,
});
if (error2) {
console.log('Sign in error:', error2.message);
return;
}
const userId = data.user.id;
const { data1, error: insertError } = await supabase
.from('user_info')
.insert([
{
name: name,
lname: lname,
id: userId,
},
]);
if (insertError) {
console.log('Insert error:', insertError.message);
return;
}
navigation.navigate('User-home');
} catch (error) {
console.log('Error:', error.message);
}
};
英文:
i used the data returned from the login and that's how i accessed it
const handlesignup = async () => {
try {
let { error } = await supabase.auth.signUp({
email: email,
password: password,
});
if (error) {
console.log('Sign up error:', error.message);
return;
}
const { data, error:error2 } = await supabase.auth.signInWithPassword({
email: email,
password: password,
})
if (error2) {
console.log('Sign in error:', error2.message);
return;
}
const userId = data.user.id;
//console.log('userId:', data.user);
const { data1, error: insertError } = await supabase
.from('user_info')
.insert([
{
name: name,
lname: lname,
id: userId,
},
]);
if (insertError) {
console.log('Insert error:', insertError.message);
return;
}
navigation.navigate('User-home');
//console.log('Sign up successful!');
//console.log('User ID:', userId);
} catch (error) {
console.log('Error:', error.message);
}
};
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论