【问题标题】:How to retrieve another user's info like email and displayName in Firebase?如何在 Firebase 中检索其他用户的信息,例如电子邮件和 displayName?
【发布时间】:2017-08-20 20:57:23
【问题描述】:

我在 Firebase 中有一个 users 节点存储每个用户的信息,但不包括 displayName andemail`,它位于 firebase auth DB 中。

有一天,我意识到我还需要用户的displayNameemail 信息。 例如,在另一个用户创建的页面中,我想显示该用户的 displayName 和电子邮件。

鉴于此

  1. displayNameemail 不存储在 users 节点下,
  2. 用户的 uniqueId 已知

是否可以从 firebase auth DB 中检索用户的 displayNameemail(普通用户或管理员)? 或者我应该为已经在 firebase 中创建的用户做什么?

谢谢, D

【问题讨论】:

    标签: firebase firebase-realtime-database firebase-authentication


    【解决方案1】:

    使用 AdminSDK 可以像 here 解释的那样。

    在文档中,每种方法都有示例,但在你的情况下,我猜你搜索过这个

    admin.auth().getUser(uid)
        .then(function(userRecord) {
            // See the UserRecord reference doc for the contents of userRecord.
            console.log("Successfully fetched user data:", userRecord.toJSON());
        })
        .catch(function(error) {
            console.log("Error fetching user data:", error);
        });
    

    您可以执行userRecord.displayName 之类的操作。完整界面是here

    【讨论】:

    • 感谢您的帮助!所以我知道任何需要由客户端检索的其他用户数据都应该保存在users 节点中,无论身份验证数据库是否有它。我说的对吗?
    • 是的。因此,您在 Cloudfunctions for Firebase 中有用户退出触发器
    猜你喜欢
    • 2018-08-26
    • 2019-05-06
    • 1970-01-01
    • 1970-01-01
    • 2020-12-11
    • 1970-01-01
    • 2021-07-25
    • 2019-04-21
    • 2020-06-09
    相关资源
    最近更新 更多