首页 > 解决方案 > 无论如何要从 Firebase 身份验证 wintout 登录中检索 uid

问题描述

是否有办法从 Firebase Authentication wintout 登录中检索 uid,只能使用注册时提供的电子邮件

标签: javascriptreactjsreact-nativefirebase-authentication

解决方案


客户端 SDK 中没有通过用户电子邮件地址查找 UID 的功能。但该功能存在于 Firebase 的 Admin SDK 中。例如,在(服务器端)Node.js 中,您可以这样做:

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);
  });

此功能仅在 Admin SDK 中的原因是它们将在受信任的环境中使用,并且对于在客户端中具有此功能的许多应用程序可能不需要。通过将 API 置于受信任的环境中,例如您的开发机器、您控制的服务器或 Cloud Functions,您可以在您的用例需要时将功能公开给您的应用程序。

或者,您可以将必要的信息存储在数据库中(例如 Firebase 的实时数据库或 Cloud Firestore),并允许用户从那里进行查找。

另请参阅:Firebase 通过电子邮件获取用户 UID


推荐阅读