加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 站长学院 > MsSql教程 > 正文

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

发布时间:2020-12-12 16:27:39 所属栏目:MsSql教程 来源:网络整理
导读:我想添加一个属性到Firebase用户对象. user documentation表示,我只能使用Firebase实时数据库存储其他属性. 我不确定这在实践中如何运作. 以下是什么意思在实践中? You cannot add other properties to the Firebase User object directly; instead,you can
我想添加一个属性到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)

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

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读