更新时间:2023-12-03 16:27:10
如果要在受信任的服务器上通过电子邮件查找用户,则可以使用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(...
另请参阅: