我想添加一个属性到Firebase用户对象. user documentation表示,我只能使用Firebase实时数据库存储其他属性.
我不确定这在实践中如何运作.
以下是什么意思在实践中?
You cannot add other properties to the Firebase User object directly;
instead, you can store the additional properties in your Firebase
Realtime Database.
我解释如下:
“您不能修改FIRUser对象的属性,但您可以将其与其他对象组合”
我找到了这样我设置的设置功能documentation:
var userRef = ref.child("users");
userRef.set({
newfield: "value"
});
这是一个明智的做法吗?
最佳答案
你几乎在那里在传统Firebase文档中,我们在storing such additional user data上有一节.
关键是在用户的uid下存储附加信息:
let newUser = [
"provider": authData.provider,
"displayName": authData.providerData["displayName"] as? NSString as? String
]
// Create a child path with a key set to the uid underneath the "users" node
// This creates a URL path like the following:
// - https://<YOUR-FIREBASE-APP>.firebaseio.com/users/<uid>
ref.childByAppendingPath("users")
.childByAppendingPath(authData.uid).setValue(newUser)
我添加了一个注释,我们应该在新的文档中添加这些信息.我们只需要找到一个很好的地方.
相关文章
转载注明原文:数据库设计 – Firebase:设置其他用户属性 - 代码日志