4

I have a strange error when I work in firebase flutter facebook login. It always results in null email. And when I see the firebase console, the email field is registering with _.
I have searched on StackOverflow to figure out this error but could not succeed. And I have followed the steps in facebook account for iOS setup. What kind of possible reasons are there?

And If I try to log in with facebook, this shows "You previously logged in to this app with facebook account" even though I never logged in before... Help me guys. I am struggling with this issue for more than 10 days!!!

  // Sign in with Facebook.
static Future<Map<String, dynamic>> signInWithFacebook({bool isSignUp}) async {
  try {      
    await signOutFacebook();
    UserCredential userCredential;  
    // Trigger the sign-in flow
    List<String> permissions = ['email', 'public_profile'];
    final LoginResult loginResult = await FacebookAuth.instance.login(permissions: permissions);
    // Create a credential from the access token
    final OAuthCredential facebookAuthCredential = 
    FacebookAuthProvider.credential(loginResult.accessToken.token);
    // Once signed in, return the UserCredential
    userCredential = await FirebaseAuth.instance.signInWithCredential(facebookAuthCredential);
    final User user = userCredential.user;      
    print("User info after facebook login ${user.providerData[0].email} ${user.uid}");
    // ************************************** This is showing null email ***** //
    if (isSignUp) {
      Map<String, dynamic> resultOfSaveSocialUserToDatabase = await saveSocialUserToDatabase(user, 'facebook');
      return resultOfSaveSocialUserToDatabase;
    } else {
      Map<String, dynamic> resultOfValidateSocialLogin = await validateSocialLogin(user, 'facebook');
      return resultOfValidateSocialLogin;
    }      
  } catch (e) {
    print(e);
    return {'success': false, 'message': "Sign up with social account failed"};
  }
}  

app screenshot firebase facebook provider firebase users

Speeder
  • 120
  • 3
  • 12
  • Does [this](https://stackoverflow.com/a/37741550/15117201) help? – Jahn E. Dec 11 '21 at 11:50
  • Hi. @JahnE. I have already checked that URL. But was not helpful. I have already followed all of them in that issue. I am sorry. – Speeder Dec 11 '21 at 20:46

2 Answers2

2

This happens cause you might have created your facebook account using your phone number instead of email.

So, it turns out to be an empty email address as an empty identifier.

You can try out with a different fb account which may be created using an email address instead of phone number.

Jay Mungara
  • 6,663
  • 2
  • 27
  • 49
0

This can also happen when the user elects to not share his email when login in with his FB account for the first time.

enter image description here