微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

数据库设计 – Firebase:设置其他用户属性

我想添加一个属性到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)

添加一个注释,我们应该在新的文档中添加这些信息.我们只需要找到一个很好的地方.

原文地址:https://www.jb51.cc/mssql/82264.html

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐