且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何通过用户电子邮件 Firebase android 获取用户 ID?

更新时间:2023-12-03 16:19:04

如果您想在受信任的服务器上通过电子邮件查找用户,您可以使用 Firebase Admin SDK.来自关于检索用户数据的文档:

If you want to look up a user by their email on a trusted server, you can use the Firebase Admin SDK. From the documentation on retrieving user data:

admin.auth().getUserByEmail(email)
  .then(function(userRecord) {
    // See the tables above for the contents of userRecord
    console.log("Successfully fetched user data:", userRecord.toJSON());
  })
  .catch(function(error) {
    console.log("Error fetching user data:", error);
  });

用于 Firebase 身份验证的客户端 SDK 仅提供对当前经过身份验证的用户的个人资料的访问.他们不提供通过电子邮件地址查找用户的方法.为了允许客户端查找,常用的方法是将 UID-by-email-address 存储在数据库中:

The client SDKs for Firebase Authentication only provide access to the profile of the currently authenticated user. They don't provide a way to look up a user by their email address. To allow client-side lookup, the common way to do so is to store the UID-by-email-address in the database:

"emailToUid": {
    "SumOne@domain,com": "uidOfSumOne",
    "puf@firebaseui,com": "uidOfPuf"
}

通过这个简单的列表,您可以通过以下编码的电子邮件地址查找 UID:

With this simple list, you can look up the UID by the encoded email address from:

ref.child("emailToUid").child("SumOne@domain,com").addSingleValueEventListener(...

另见: