【问题标题】:How to get the user id of a email from firebase email authentication如何从 Firebase 电子邮件身份验证中获取电子邮件的用户 ID
【发布时间】:2019-06-25 03:13:14
【问题描述】:

我想从 firebase authentication 访问电子邮件的 id (或 uid )。它不是当前用户 id 的 id,所以我不能使用 firebase.auth().currentUser.uid。而且我也无法在注册时将 uid 存储在数据库中并获取它。无论如何直接从firebase身份验证系统获取它

【问题讨论】:

    标签: android reactjs firebase react-native firebase-authentication


    【解决方案1】:

    Firebase Admin SDK 支持通过电子邮件查找用户信息:

    admin.auth().getUserByEmail(email)
      .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 对象。

    如果提供的电子邮件不属于现有用户或由于任何其他原因无法获取该用户,则 Admin SDK 会引发错误。

    参考:https://firebase.google.com/docs/auth/admin/manage-users

    【讨论】:

    • 当我使用此代码时,我收到一个错误,找不到变量 admin
    • 你使用 firebase-adnin 吗?npm install firebase-admin --save 要在应用程序中使用该模块,请从任何 JavaScript 文件中要求它: var admin = require('firebase-admin');如果您使用的是 ES2015,则可以改为导入模块: import * as admin from 'firebase-admin';
    • ohhh...我忘了这样做...还有一件事要问,如何只从这个json中检索uid
    • userRecord.uid 在回调中
    【解决方案2】:

    使用 admin.auth().getUserByEmail(email)

    【讨论】:

      猜你喜欢
      • 2019-05-01
      • 2023-03-18
      • 2021-11-21
      • 2021-04-04
      • 2018-02-10
      • 1970-01-01
      • 2016-01-27
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多