Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
Nyamkhuub opened this issue Jan 4, 2020 · 13 comments
Labels
type: bug Something isn't working

Comments

@Nyamkhuub
Copy link

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?

@Nyamkhuub Nyamkhuub added the type: bug Something isn't working label Jan 4, 2020
@Nyamkhuub Nyamkhuub changed the title [<firebase_auth>] <PlatformException(ERROR_INVALID_EMAIL, The email address is badly formatted., null)> [firebase_auth] PlatformException(ERROR_INVALID_EMAIL, The email address is badly formatted., null) Jan 4, 2020
@Nyamkhuub
Copy link
Author

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

Solved!

@vainas-brazdeikis
Copy link

vainas-brazdeikis commented Apr 6, 2020

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.

@gibbieyh
Copy link

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

@vainas-brazdeikis
Copy link

Could this issue be reopened?

@Nyamkhuub
Copy link
Author

@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 'test@gmail.com '. 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!

@tiaralogan
Copy link

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

@ahabib91
Copy link

@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 'test@gmail.com '. 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.

@ShadabAShaikh
Copy link

@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 'test@gmail.com '. 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.

@ezazulhaq
Copy link

Thank you for solution.

@umakanth-pendyala
Copy link

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

@RoberVF
Copy link

RoberVF commented Jun 13, 2020

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

@Blazkowiz47
Copy link

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

@dukesy710
Copy link

dukesy710 commented Jul 24, 2020

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

keyboardType: TextInputType.emailAddress

@firebase firebase locked and limited conversation to collaborators Aug 4, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
type: bug Something isn't working
Projects
None yet
Development

No branches or pull requests