-
Notifications
You must be signed in to change notification settings - Fork 27.8k
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
How to handle firebase auth errors? #20223
Comments
i think this issue is the appropriate spot...
if a user enters the wrong SMS code when doing phone number auth -- it looks like this this may be getting addressed in flutter/plugins#678 if it's similar to #18312 ? |
@joshkendrick My upcoming patch will address this. and #18312 |
sounds great! |
@joshkendrick , will your update allow us to catch all Firebase exceptions that currently can't be handled? |
Is there any hack, to identify the errors correctly in android? Because now the error code is not provided. :( |
As @HerrNiklasRaab said now it returns this |
Stuck with the same issue. Any work around? |
Any update on this? I need error code to display custom error message |
+1.. this is a core part of the firebase auth experience. Really difficult to release an app into the wild where all sorts of auth errors might crop up. The PlatformException thrown freezes up the whole app and makes it unusable until a recompile.. |
@suparnavg Sorry why you are saying that this auth errors freezes up the app and it's not unusable until a recompile? In the code that I've included it doesn't happen. You are maybe forgetting the |
@knitero @anderscheow @HerrNiklasRaab See the updated question for a temporary solution. |
@riccardoratta Thanks, this is bad, but the best possible solution :) |
@riccardoratta The solution you proposed is what I wanted to prevent :( |
@anderscheow Yes, it's the point of the issue. We need a cross platform way (for example by an enum) to know exactly what kind of error firebase auth is throwing. The temporary fix I've included is if you have an application that need to be publicated as soon as possible and you don't know how to proceed. |
My fix will be merged soon and this can be resolved. |
Is the fix release? |
Thanks @riccardoratta will give it a shot. My comment was meant for the original question, not your solution :) |
Is there meanwhile a solution to this problem? I need to something like this: try {
await _auth.createUserWithEmailAndPassword(email: email, password: password);
return 0;
} catch (error) {
return error;
} So I can distinguish the errors but I could find any solution to this. |
Any updates on this? |
This issue is closed.
|
You can do
You will get the error only like
|
On Android, you can grab the code from the exception. I can't test on iOS atm but is there a reason not to use this? catch (e) {
print(e.code);
switch (e.code) {
case 'ERROR_INVALID_EMAIL':
authError = 'Invalid Email';
break;
case 'ERROR_USER_NOT_FOUND':
authError = 'User Not Found';
break;
case 'ERROR_WRONG_PASSWORD':
authError = 'Wrong Password';
break;
default:
authError = 'Error';
break;
}
} |
I implemented the error handling. You do not want to use https://api.flutter.dev/flutter/services/PlatformException-class.html |
@mikecbone, where can we find all these existing error messages? Firebase official docs don't have it... And i can't find anywhere... |
You can find a list of errors here. You just need to replace So Not the best solution I know, but it does seem to work. |
Oh boy, so that's the secret... Thank you! |
I documented the error codes in the source on each one of the FirebaseAuth functions. So just check the function comments you are calling. |
I'll check it out! Thank you! |
Error 404 |
Indeed |
This issue has been moved to firebase/flutterfire#725. Any further collaboration will be done there. |
I made a gist with all the auth errors from firebase with an example https://gist.github.com/nikhilmufc7/6b74a3c12a6e2d3284942d40ff583e37 |
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 |
I'm trying to build a login page with firebase auth plugin. But I don't know how to handle auth errors in a cross-platform way. For example, this are some
PlatformException
that I get when the user type the wrong password/email or there are a network issue.On iOS:
On Android:
The format is: code, message, details. In Android I get a code:
exception
, what does it mean? And also in iOS I always get a message:FIRAuthErrorDomain
and not any standard code listed here.The code:
Temporary fix (don't rely on this solution)
In the meantime the problem can be fixed (see bottom for warning on this solution) with something like that:
Warning: The problem, that I would like to emphasize with this issue, it's that you can't rely too much in this solution because a simple FirebaseAuth update can screw it up. Also if you choose this way be sure to lock the
firebase_auth: ?.?.?
to a specific version in the pubspec.yaml file.Flutter doctor
The text was updated successfully, but these errors were encountered: