【发布时间】:2023-03-06 10:58:02
【问题描述】:
我的应用中有一个signup screen,其中包含一些内容:
full name、email 和 password。
我想将用户full name 和将来的phone number(例如)添加到实时数据库中。
我该怎么做?
我正在使用firebase cloud functions 中的onCreate 将photoUrl 和email 添加到数据库中,但找不到添加我自己的属性的方法,例如phone number,city,@ 987654333@等
最终,我想要一个包含上述所有属性的注册表单。 我该怎么做?
这是我的onCreate 方法:
const functions = require('firebase-functions');
const admin = require('firebase-admin');
admin.initializeApp(functions.config().firebase);
const ref = admin.database().ref()
exports.createUserAccount = functions.auth.user().onCreate(event=>{
const uid = event.data.uid
const email = event.data.email
const photoUrl = event.data.photoUrl || 'https://vignette1.wikia.nocookie.net/paulblartmallcop/images/9/9c/Person-placeholder-male.jpg/revision/latest?cb=20120708210100'
const newUserRef = ref.child(`/users/${uid}`)
return newUserRef.set({
photoUrl: photoUrl,
email: email,
})
});
如何向用户添加更多属性?
【问题讨论】:
-
你的客户端代码是什么样子的?
-
这是一个简单的注册表单,例如:电子邮件、密码、姓名、电话号码。使用我现在的方法,email 和 photoUrl 都保存到数据库中,如何将表单中的其余数据保存到数据库中?
-
我假设您使用
createUserWithEmailAndPassword或类似的东西来创建用户,成功后您需要创建另一个函数来添加您的其他详细信息 -
你说得对,我正在使用 createUserWithEmailAndPassword,但是,这个 onCreate 是在 createuseremailandpassword 之后触发的,并将电子邮件添加到数据库中我需要它来将姓名和电话添加到数据库中
-
是的,所以您需要使用来自客户端的其他附加字段来更新
users/userId引用
标签: javascript firebase react-native firebase-realtime-database firebase-authentication