Strange Error: flutter firebase facebook login results empty email and registering _ in firebase console. What to do now?

264

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.

Share:
264
Speeder
Author by

Speeder

I am struggling hard to do my work at 100% quality. React, React Native and Flutter are my best skill sets.

Updated on January 02, 2023

Comments

  • Speeder
    Speeder over 1 year

    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