Cannot retrieve email from FirebaseAuthentication on Android/iOS

孤者浪人 提交于 2020-01-25 02:58:06

问题


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.

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.

When I call AuthResult.getAdditionalUserInfo().getProfile after the FirebaseAuth login, I can see that the email is present in the map.

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?


回答1:


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.

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.




回答2:


@Billda

But we can get the email from the task.isSuccessful() method.

Just use this snippet in on success task from the firebase:

Map profile = task.getResult().getAdditionalUserInfo().getProfile();

Object email = profile.get("email");

Obtaining the email from the use though we use the same email form Facebook and Google log in accounts.

By this way, you can get the email of the particular user

Thank you. Can you clearly post the problem where you are encountering it?

Because there are many possibilities where we can get the email as null.



来源:https://stackoverflow.com/questions/54801747/cannot-retrieve-email-from-firebaseauthentication-on-android-ios

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!