Flutterfire: [firebase_auth] PlatformException(ERROR_INVALID_EMAIL, The email address is badly formatted., null)

Created on 4 Jan 2020  路  13Comments  路  Source: FirebaseExtended/flutterfire

Hello developers
that is my exception:

PlatformException(ERROR_INVALID_EMAIL, The email address is badly formatted., null)

final FirebaseAuth _auth = FirebaseAuth.instance;
  Future<FirebaseUser> signIn(userName, userPassword) async {
    print(userName);
    print(userPassword);
    FirebaseUser userData;
    try {
      userData = (await _auth.signInWithEmailAndPassword(email: userName, password: userPassword)).user;
      //userData = (await _auth.signInWithEmailAndPassword(email: userName.toString(), password: userPassword.toString())).user;
    } catch(error) {
      print(error);
    }
    if (userData != null) {
      print(userData);
      return userData;
    } 
    return null; 
  }

How to solve that issue?

bug

Most helpful comment

I should just use trim function. Looks like that
userData = (await _auth.signInWithEmailAndPassword(email: userName.trim(), password: userPassword)).user;

Solved!

All 13 comments

I should just use trim function. Looks like that
userData = (await _auth.signInWithEmailAndPassword(email: userName.trim(), password: userPassword)).user;

Solved!

Did you figure out why? If user provides correct email it should not require trim.

Was running into the same issue and trim solved it too. But this is very strange.

Hello,
Thank you for the solutions. I had the same problem, with similar code as yours. I managed to fix it use the trim() too! Although Im still confused how trim() can fix the problem. Can anyone care to explain?
Thank you

Could this issue be reopened?

@gibbieyh @vainas-brazdeikis , In my case, I am using tab to switch email text field to password field on an emulator. So, of course you can test it on an emulator/android/. If you use tab to switch fields, email text field value is contain a white space like '[email protected] '. Because of white space my application throw this exception, I believe. Finally, I just using trim function to remove white space.
Also, another solution is you have to use email validator. For instance https://pub.dev/packages/email_validator

I believe, My answer will remove your confuse!

I am having the same problem, but removing the whitespaces isn't fixing it. Any other ideas on how to solve this problem

@gibbieyh @vainas-brazdeikis , In my case, I am using tab to switch email text field to password field on an emulator. So, of course you can test it on an emulator/android/. If you use tab to switch fields, email text field value is contain a white space like '[email protected] '. Because of white space my application throw this exception, I believe. Finally, I just using trim function to remove white space.
Also, another solution is you have to use email validator. For instance https://pub.dev/packages/email_validator

I believe, My answer will remove your confuse!

You are a hero, thank you boss for solving this issue.

@gibbieyh @vainas-brazdeikis , In my case, I am using tab to switch email text field to password field on an emulator. So, of course you can test it on an emulator/android/. If you use tab to switch fields, email text field value is contain a white space like '[email protected] '. Because of white space my application throw this exception, I believe. Finally, I just using trim function to remove white space.
Also, another solution is you have to use email validator. For instance https://pub.dev/packages/email_validator

I believe, My answer will remove your confuse!

Thank you so much. Just spent five hours trying to figure out why it wasn't working until I got to your response. I don't even understand why it would add a space if you hit tab. What sort of absurd reason could there be to add a space at the end of the field if someone hits tab in an emulator.

Thank you for solution.

Thank you for the solution. works for me when I add the trim

Works me! Just adding .trim() to email. Thanks!

Yeah trim() works!!! its probably due to the space which gets added sometimse after typing the email

Can avoid adding a package or using .trim() by setting the textformfield type

keyboardType: TextInputType.emailAddress

Was this page helpful?
0 / 5 - 0 ratings