【问题标题】:Firebase retrieving user.email with user idFirebase 使用用户 ID 检索 user.email
【发布时间】:2016-08-30 16:21:36
【问题描述】:

我目前正在使用 Firebase 来管理我的用户。我喜欢我可以将我的用户信息(例如电子邮件、photoUrl 和其他信息)存储到

中的想法
let user = FIRAuth.auth()?.currentUser

user?.updateEmail("user@example.com") { error in
  if let error = error {
    // An error happened.
  } else {
    // Email upenter code heredated.
  }
}

当然,这仅适用于当前登录用户,如果我想通过使用另一个用户 ID 来检索另一个用户的相同信息,我该如何检索它。

【问题讨论】:

  • 没有内置的 API 可以通过用户的 UID 来查找用户的信息。出于这个原因,大多数开发人员将用户信息列表保存在另一个数据源(例如 Firebase 数据库)中。见stackoverflow.com/questions/28735377/…

标签: swift firebase firebase-authentication


【解决方案1】:

您可以在数据库的 JSON 树中创建一个“用户”子级,并通过您可以通过 FIRAuth.auth()?.currentUser.uid 获得的用户 ID 分隔每个用户。

所以你的 JSON 树看起来像这样:

"root"
    "users"
        "userID12345"
            "email"
            "photoURL"

然后,您可以通过调用从 Firebase 中提取数据:

FIRDatabase.database().reference().child("users").observeEventType(.Value, withBlock: { (snapshot) in
//store the snapshot.value in a dictionary and read your data from there
})

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-09-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-11-15
    • 2018-03-21
    • 2017-06-10
    相关资源
    最近更新 更多