Add FirebaseAuthException.errorCode to "firebase-auth" for iOS/Android/...
Opened this issue · 2 comments
AlexeySAntonov commented
TomerGlick commented
I didn't get how to even get the exception -> using
auth.signInWithEmailAndPassword(email, password)
but how to implement those functions?
AlexeySAntonov commented
@TomerGlick You can try smth like this:
suspend fun signInWithEmail(email: String, password: String): FirebaseSignInResult {
return try {
val result = auth.signInWithEmailAndPassword(email, password)
FirebaseSignInResult.Success
} catch (e: Exception) {
handleFailure(e)
}
}
private fun handleFailure(e: Exception): FirebaseSignInResult {
return when (e) {
is FirebaseAuthWeakPasswordException -> FirebaseSignInResult.Failure.WeakPassword
is FirebaseAuthInvalidCredentialsException -> handleInvalidCredentialsFailure(e)
is FirebaseAuthInvalidUserException -> handleInvalidUserFailure(e)
is FirebaseAuthUserCollisionException -> FirebaseSignInResult.Failure.UserCollision
is FirebaseAuthEmailException -> FirebaseSignInResult.Failure.InvalidEmail
else -> FirebaseSignInResult.Failure.Unexpected
}
}
sealed interface FirebaseSignInResult {
data object Success : FirebaseSignInResult
sealed interface Failure : FirebaseSignInResult {
data object InvalidPassword : Failure
data object InvalidEmail : Failure
data object WeakPassword : Failure
data object UserDisabled : Failure
data object UserNotFound : Failure
data object UserCollision : Failure
data object Unexpected : Failure
}
}