问题描述
我正在使用Google/Facebook社交登录名在我的应用程序中使用FirebaseAuth,并且我们允许用户在首次登录后更改他的电子邮件,因为我们拥有自己的后端用户管理部门,并且会在注册表格中预先填写此电子邮件.
I am using FirebaseAuth in my app with Google/Facebook social logins and we allow user to change his email after first login because we have our own backend with user management and we prefill this email in the registration form.
似乎我突然无法从 FirebaseUser.getEmail()
方法中检索用户的电子邮件地址.当我尝试使用Facebook/Google登录SDK检索电子邮件时,我可以对其进行检索,因此这不是隐私问题.我的电子邮件已经过验证,因此这也不是问题.
It seems that all of a sudden I can't retrieve user's email address from FirebaseUser.getEmail()
method. When I try to retrieve email using Facebook/Google login SDKs I can retrieve it so it's not a privacy issue. My email is verified so this should not be problem neither.
在FirebaseAuth登录后调用 AuthResult.getAdditionalUserInfo().getProfile
时,我可以看到 email
出现在地图中.
When I call AuthResult.getAdditionalUserInfo().getProfile
after the FirebaseAuth login, I can see that the email
is present in the map.
我已经在此处阅读了一些问题,以便用户无法在Firebase控制台中看到电子邮件,但可以看到所有内容.Firebase auth SDK的版本为 16.1.0
.此行为在我们的iOS应用程序中也可见,因此与Android无关,但仍无法弄清楚为什么会发生这种情况.文档表示它将在登录时预先填充.
I've read some question here on SO that user could not see an email in Firebase Console but there is everything visible. Version of Firebase auth SDK is 16.1.0
. This behavior is also visible in our iOS app so it's not maybe Android related, but still can't figure out why is this happening. The docs say that it will be prepopulated on login.
我弄错了吗?还是获取此电子邮件的正确方法是什么,以便我可以用它来预先填充表单?
Do I get it wrong? Or what should be the right way to obtain this email so I can prepopulate my form with it?
推荐答案
使用每封电子邮件多个帐户"设置时,顶级电子邮件 user.getEmail()
对于非电子邮件为null(电子邮件/密码或电子邮件链接)帐户.如果提供者存储在索引0中,则可以从 user.getProviderData().get(0).getEmail()
列表中获取电子邮件.
When using "multiple accounts per email" setting, the top level email user.getEmail()
is null for non-email (email/password or email link) accounts. You can get the email from the user.getProviderData().get(0).getEmail()
list, provided the provider is stored in index 0.
这是因为顶级电子邮件是唯一的,并且没有2个帐户可以共享.因此,对于使用该电子邮件创建的任何其他OAuth帐户(如Facebook,Google等),顶级电子邮件为空.
This is because the top level email is unique and no 2 accounts can share that. As a result, the top level email is null for any additional OAuth account created like Facebook, Google, etc with that email.
这篇关于无法在Android/iOS上从FirebaseAuthentication检索电子邮件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!