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

FirebaseAuthPlugin: Error codes are not forwarded to Dart #18312

Closed
escamoteur opened this issue Jun 8, 2018 · 25 comments · Fixed by flutter/plugins#775
Closed

FirebaseAuthPlugin: Error codes are not forwarded to Dart #18312

escamoteur opened this issue Jun 8, 2018 · 25 comments · Fixed by flutter/plugins#775
Labels
p: firebase Firebase plugins package flutter/packages repository. See also p: labels.

Comments

@escamoteur
Copy link
Contributor

Hi,

I just found out that if an error happens on the FirebaseAuth side like "email already used" I will only get an

      throw new PlatformException(code: errorCode, message: errorMessage, details: errorDetails);

with errorCode = "exception" and an error message that isn't localized which isn't really helpful.

Looking at the Java side of the plugin made it obvious

 private class SignInCompleteListener implements OnCompleteListener<AuthResult> {
    private final Result result;

    SignInCompleteListener(Result result) {
      this.result = result;
    }

    @Override
    public void onComplete(@NonNull Task<AuthResult> task) {
      if (!task.isSuccessful()) {
        Exception e = task.getException();
        result.error(ERROR_REASON_EXCEPTION, e.getMessage(), null);
      } else {
        FirebaseUser user = task.getResult().getUser();
        ImmutableMap<String, Object> userMap = mapFromUser(user);
        result.success(userMap);
      }
    }
  }

This should actually be a [FirebaseAuthException](https://firebase.google.com/docs/reference/android/com/google/firebase/auth/FirebaseAuthException)

which has a `GetErrorCode` method. Please change that so that Apps can react on error conditions with their own texts.
@timsneath
Copy link
Contributor

Good catch - thanks, @escamoteur. Adding @collinjackson.

@zoechi
Copy link
Contributor

zoechi commented Jun 8, 2018

Similar to #13027

@escamoteur
Copy link
Contributor Author

Difference is that for FirebaseAuth you get an exception on the Dart side but no error code

@chinmaygarde chinmaygarde added plugin p: firebase Firebase plugins labels Jun 9, 2018
@twpochuan
Copy link

twpochuan commented Jul 10, 2018

After removing the 'google_sign_in' from dependencies, the error codes came back.
It seems something goes wrong or override the exception when 'google_sign_in' is added into the dependencies.

EDIT:
I got the error codes back on ios, but there is still no error codes on Android...

Update:
I tried to trace the code and decoded the raw response from firebase auth:

without 'google_sign_in':

iOS: flutter: \^G�Error 17008\^G\^RFIRAuthErrorDomain\^G%The email address is badly fo<…>
Android: I/flutter ( 1450): �	exception�%The email address is badly formatted.

with 'google_sign_in':

iOS: flutter: \^G\^Nsign_in_failed\^G\^RFIRAuthErrorDomain\^G%The email address is badly <…>
Android: I/flutter ( 4105): �	exception�%The email address is badly formatted.

@eseidelGoogle
Copy link
Contributor

This looks like a quick fix. @bparrishMines or @kroikie may be interested.

@MateusPalomo
Copy link

MateusPalomo commented Sep 4, 2019

If you encounter something like below,
this is because there is an extra spacing at the end of your email. ==>
I/flutter (14294): Error PlatformException(exception, The email address is badly formatted., null)

Try delete extra spacing,

@kroikie
Copy link

kroikie commented Oct 13, 2019

@escamoteur

This issue has been moved to firebase/flutterfire#802. Any further collaboration will be done there.

@reinaldobrazpereira
Copy link

Obrigado MateusPalomo.
Era um espaço extra mesmo, e fiquei algum tempo em cima deste erro.
Abraço.

@VisheshAtWork
Copy link
Contributor

Same issue. Any work around ?

@KristianBalaj
Copy link

Still an issue.

@folivi
Copy link

folivi commented Oct 12, 2020

Hi all,
Has this been fixed? Tried calling createUserWithEmailAndPassword inside a try catch block both handling platformException and FirebaseAuthException but the app litterally crashes when an on the email-exists error

@escamoteur
Copy link
Contributor Author

please report here: firebase/flutterfire#802

@escamoteur
Copy link
Contributor Author

@kroikie unfortunately the other thread got locked which I find pretty strange if this isn't fixed yet. I am pretty sure there was a PR with this fix from @slightfoot a long time ago

@slightfoot
Copy link
Member

I did fix this. But the FlutterFire migration work changed the error codes to the web sdk ones. Either way it could be a platform specific regression. @Salakar would know.

@Salakar
Copy link
Member

Salakar commented Oct 12, 2020

cc @Ehesp

@muhammadsqln
Copy link

How is this still fixed

@escamoteur
Copy link
Contributor Author

@muhammadsqln does it still not work?

@EriKWDev
Copy link

This is still a problem.. I'm following the very basic usage tutorial code on https://firebase.flutter.dev/docs/auth/usage but PlatformException is thrown and not catched in debug mode on VSCode which makes debugging basically unbearable. I'm not using google_sign_in

@escamoteur
Copy link
Contributor Author

What do you mean by that VS code isn't catching the PlatformException? did you enable break on all exceptions?

@EriKWDev
Copy link

EriKWDev commented Jan 22, 2021

Sorry, I meant the opposite xP I don't want VSCode to stop on PlatformException but it goes ahead and does it anyway... I'm running the code

UserCredential userCredential;

try {
  userCredential = await FirebaseAuth.instance.signInWithEmailAndPassword(email: email, password: password);
} on FirebaseAuthException catch (e) {
  if (e.code == 'user-not-found') {
    print('No user found for that email.');
  } else if (e.code == 'wrong-password') {
    print('Wrong password provided for that user.');
  }
} on PlatformException catch(e) {
  print(e);
}

on an Android emulator from VSCode debug mode. I have "Break on All Exceptions" turned off, but when the code is called the debugger stops anyway on PlatformException from message_codecs.dart

image
image

The error code is there, but something doesn't catch it..

@Ehesp
Copy link
Member

Ehesp commented Jan 22, 2021

Please create new issues on the FlutterFire repo so maintainers have visibility. This will not be seen/addressed here.

@escamoteur
Copy link
Contributor Author

if you hit continue it does not get caught int your 'on PlatformException'?

@EriKWDev
Copy link

Please create new issues on the FlutterFire repo so maintainers have visibility. This will not be seen/addressed here.

Will do!

@EriKWDev
Copy link

if you hit continue it does not get caught int your 'on PlatformException'?

No, it doesn't.

@github-actions
Copy link

github-actions bot commented Aug 6, 2021

This thread has been automatically locked since there has not been any recent activity after it was closed. If you are still experiencing a similar issue, please open a new bug, including the output of flutter doctor -v and a minimal reproduction of the issue.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Aug 6, 2021
@flutter-triage-bot flutter-triage-bot bot added the package flutter/packages repository. See also p: labels. label Jul 5, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
p: firebase Firebase plugins package flutter/packages repository. See also p: labels.
Projects
None yet
Development

Successfully merging a pull request may close this issue.