gpt4 book ai didi

javascript - 火力基地 : setting additional user properties

转载 作者:行者123 更新时间:2023-12-03 12:15:54 27 4
gpt4 key购买 nike

我想向 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)

我添加了一条说明,我们也应该在新文档中添加此信息。我们只需要为它找到一个好地方。

关于javascript - 火力基地 : setting additional user properties,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37415863/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com