Firebase Facebook登录重定向返回空电子邮件 [英] Firebase Facebook login with redirect returning null email
问题描述
如果我有以下代码:
function facebookSignin(){var provider = new firebase.auth.FacebookAuthProvider(); provider.addScope(电子邮件); 。firebase.auth()signInWithRedirect(提供商); } firebase.auth()。getRedirectResult()。then(function(result){if(result.credential){var token = result.credential.accessToken;} var user = result.user; console.log(result);} ).catch(function(error){var errorCode = error.code; var errorMessage = error.message; var email = error.email; var credential = error.credential; console.log(errorMessage);}); $
我试图从Facebook登录电子邮件,但是当我打印用户对象,我得到一个 null
电子邮件。我已经包含了控制台中打印的用户对象的屏幕截图。
这应该显示Facebook的电子邮件。您可以在Firebase控制台中启用每个电子邮件有多个帐户。新项目的默认值是每个电子邮件的单个帐户。对于从之前版本迁移Firebase项目,它们设置为每个电子邮件有多个帐户。这只会设置firebase.auth()。currentUser.email的密码帐户。对于联合帐户,它设置为空。还有另一种可能性,你正在使用的Facebook帐户是一个电话号码帐户或选择不透露电子邮件。
If I have the following code
function facebookSignin(){
var provider = new firebase.auth.FacebookAuthProvider();
provider.addScope('email');
firebase.auth().signInWithRedirect(provider);
}
firebase.auth().getRedirectResult().then(function(result) {
if (result.credential) {
var token = result.credential.accessToken;
}
var user = result.user;
console.log(result);
}).catch(function(error) {
var errorCode = error.code;
var errorMessage = error.message;
var email = error.email;
var credential = error.credential;
console.log(errorMessage);
});
I'm trying to get the email from Facebook login however when I print the user object i get a null
email. I have included a screenshot of the user object printed in the console
解决方案 Check the content of firebase.auth().currentUser.providerData[0].email. That should show the facebook email. It is possible you have enabled "multiple accounts per email" in the Firebase console. The default for new projects is single account per email. For migrating Firebase projects from the previous version, they are set to "multiple accounts per email". That will only set firebase.auth().currentUser.email for password accounts. For federated accounts, it is set to null. There is another possibility that the facebook account you are using is a phone number account or has chosen not to disclose the email.
这篇关于Firebase Facebook登录重定向返回空电子邮件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!