I'm building a login flow with Firebase Auth to authenticate users with email and password. While logging in, some things can go wrong: No account exists with the given email address, the password is wrong (...).
Does Firebase return any error code so I can add error handling? I only found the exception messages which I can use for error handling but is there any way to make this neater with error codes? I couldn't find anything in the official Firebase documentation.
auth.signInWithEmailAndPassword(email, password).addOnCompleteListener { task ->
if (task.isSuccessful) {
// Sign in success, update UI with the signed-in user's information
Log.d(TAG, "signInWithEmail:success")
}
}.addOnFailureListener { exception: Exception ->
when (exception.message) {
"There is no user record corresponding to this identifier. The user may have been deleted." -> // Handle error
"The password is invalid or the user does not have a password." ->// Handle error
else -> // Handle error
}
}