Firebase:设置其他用户属性 [英] Firebase: setting additional user properties
问题描述
我想向Firebase用户对象添加一个属性。 用户文档说,我只能使用Firebase实时数据库存储其他属性。
I'd like to add a property to a Firebase user object. The user documentation says that I can only store additional properties using the Firebase real time database.
我不确定在实践中如何运作。
以下意思是在实践中?
您不能直接向Firebase User对象添加其他属性;
,您可以将其他属性存储在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 对象,但您可以将其与其他对象组合
"you cannot modify properties of a FIRUser object but you can combine this with additional objects"
我发现设置功能文档,我插入以这种方式:
I found the set function documentation which I interpet in this way:
var userRef = ref.child("users");
userRef.set({
newfield: "value"
});
这是一个明智的做法吗?
Is this a sensible approach?
推荐答案
你几乎在那里在传统Firebase文档中,我们在存储此类附加用户数据。
You're almost there. In the legacy Firebase documentation, we had a section on storing such additional user data.
关键是在用户的 uid
下存储附加信息:
The key is to store the additional information under the user's 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)
我已经添加了一个注释,我们应该在新的文档中添加这些信息。我们只需要找到一个好的地方。
I've added a note that we should add this information in the new documentation too. We just need to find a good spot for it.
这篇关于Firebase:设置其他用户属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!