firebase_auth_demo_flutter
firebase_auth_demo_flutter copied to clipboard
PlatformException at authentication
https://github.com/bizz84/firebase_auth_demo_flutter/blob/2884b08a6eeac7c324e12884197e566661da1678/lib/app/sign_in/email_password/email_password_sign_in_page.dart#L84
I'm not getting the alert of the PlatformException when user get ERROR_WRONG_PASSWORD, ERROR_TOO_MANY_REQUESTS, etc. Does anyone knows how to fix it?
I was experiencing the same and found the following things that could be relevant/the reason (in order of importance):
- Firebase API now throws
FirebaseAuthException
instead ofPlatformException
. See e.g. the docs of signInWithEmailAndPassword() and the docs of the exception class
There are different ways the code in this repo can be changed to handle this, one example (the one I'll probably go with for now) is this:
- catch the widest Exception first, e.g. in
EmailPasswordSignInPage
class
} on Exception catch (e) {
_showSignInError(model, e);
}
and forward that for display:
_showSignInError(EmailPasswordSignInModel model, Exception exception)
- in
PlatformExceptionAlertDialog
class that's responsible for the displayPlatformExceptionAlertDialog({String title, Exception exception})
and
static String message(Exception exception) {
if (exception is FirebaseAuthException) {
return errors[exception.code] ?? exception.message;
} else if (exception is PlatformException) {
if (exception.message == 'FIRFirestoreErrorDomain') {
if (exception.code == 'Code 7') {
// This happens when we get a "Missing or insufficient permissions" error
return 'This operation could not be completed due to a server error';
}
return exception.details;
}
return errors[exception.code] ?? exception.message;
} else {
// Note: this could turn out ugly on the UI, (change it if you can't afford that)
// but at least you'll get some feedback
return exception.toString();
}
}
-
Your IDE settings could be "false-catching" the exceptions when you're in debug mode. Check this on VSCode and on Android Studio for more infos.
-
You could have similar side-effects when changing the architecture of the repo, e.g. I found myself trying to simplify things a bit but than too much :D (I think this is a brilliant repo, but overcomplicated here and there - arguably for the sake of testability, but still.)
On a sidenote: I'm not sure what the story is with the repo at the moment... Looking at the number and nature of issues it's missing maintenance power, but hopefully just temporarily. (I might try and do a pull request with point 1. when/if I can, but there are probably other problems that would need assistance too...)