Open vladmircan opened 11 months ago
It should throw the same exception, can you supply some more details on how to reproduce this?
@nbransby Hello, thanks for getting back to me! Sorry for not providing a code sample from the start but I first wanted to make sure it's not a known issue.
Anyways, I created this small app that showcases the problem I'm talking about: https://github.com/vladmircan/GitLiveFirebaseDemo
Let me know if there's anything else you need from me.
@vladmircan I looked at your sample but it just looks like you are just choosing to catch the generic exception by using the FirebaseException base class instead of one of the subclasses such as FirebaseAuthInvalidCredentialsException?
@nbransby That is true, I am catching the error as generic because otherwise the app just crashes (the thrown error is the generic FirebaseException
kind and not the specific FirebaseAuthInvalidCredentialsException
).
The app basically just throws a FirebaseException
with a message indicating that it is in fact a FirebaseAuthInvalidCredentialsException
.
However, while re-testing my repo, I noticed something:
If I also add the dependency to the native com.google.firebase:firebase-auth
, it all of a sudden starts working correctly. Is this expected behaviour?
No its not expected behavior - I think it would help if you share the full stack trace of the original FirebaseException
I have very similar issue. On android specific exception is thrown (like FirebaseAuthInvalidCredentialsException
, etc) but on iOS it just returns FirebaseAuthException
with NSError converted to string as message.
I think the bug is in the following piece of code from file auth.kt
. It seems one of the when
s always falls through to the else clause resulting in the generic exception.
I am on version 1.11.1
but the code does not seem to be changed in the latest versions.
private fun NSError.toException() = when(domain) {
FIRAuthErrorDomain -> when(code) {
FIRAuthErrorCodeInvalidActionCode,
FIRAuthErrorCodeExpiredActionCode -> FirebaseAuthActionCodeException(toString())
FIRAuthErrorCodeInvalidEmail -> FirebaseAuthEmailException(toString())
FIRAuthErrorCodeCaptchaCheckFailed,
FIRAuthErrorCodeInvalidPhoneNumber,
FIRAuthErrorCodeMissingPhoneNumber,
FIRAuthErrorCodeInvalidVerificationID,
FIRAuthErrorCodeInvalidVerificationCode,
FIRAuthErrorCodeMissingVerificationID,
FIRAuthErrorCodeMissingVerificationCode,
FIRAuthErrorCodeUserTokenExpired,
FIRAuthErrorCodeInvalidCredential -> FirebaseAuthInvalidCredentialsException(toString())
FIRAuthErrorCodeWeakPassword -> FirebaseAuthWeakPasswordException(toString())
FIRAuthErrorCodeInvalidUserToken -> FirebaseAuthInvalidUserException(toString())
FIRAuthErrorCodeRequiresRecentLogin -> FirebaseAuthRecentLoginRequiredException(toString())
FIRAuthErrorCodeSecondFactorAlreadyEnrolled,
FIRAuthErrorCodeSecondFactorRequired,
FIRAuthErrorCodeMaximumSecondFactorCountExceeded,
FIRAuthErrorCodeMultiFactorInfoNotFound -> FirebaseAuthMultiFactorException(toString())
FIRAuthErrorCodeEmailAlreadyInUse,
FIRAuthErrorCodeAccountExistsWithDifferentCredential,
FIRAuthErrorCodeCredentialAlreadyInUse -> FirebaseAuthUserCollisionException(toString())
FIRAuthErrorCodeWebContextAlreadyPresented,
FIRAuthErrorCodeWebContextCancelled,
FIRAuthErrorCodeWebInternalError -> FirebaseAuthWebException(toString())
FIRAuthErrorCodeNetworkError -> FirebaseNetworkException(toString())
else -> FirebaseAuthException(toString())
}
else -> FirebaseAuthException(toString())
}
seeing the same thing on ios side
In 2.1.0 this issue still persists.
Also there seem to be two codes missing from the toException()
method:
FIRAuthErrorCodeWrongPassword = 17009L
FIRAuthErrorCodeUserNotFound = 17011L
First of all, a huge thank you for the work you're doing here! Now onto my issue:
I am in the process of migrating my app to
Kotlin Multiplatform
and I noticed some discrepancies in the wayFirebase
exceptions are thrown. Whereas the native SDK throws specific errors such asFirebaseAuthInvalidCredentialsException
thegitlive
variant throws a genericFirebaseException
(with a descriptive message to be fair) thus making the error handling more difficult.N.B. I am in the early stages of my transition so I don't know if the same applies to other Firebase libraries as well.
Please let me know if this is an inherent limitation or if steps could be taken to improve this. Thanks!