Skip to content
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

Add FirebaseAuthException.errorCode to "firebase-auth" for iOS/Android/... #673

Open
AlexeySAntonov opened this issue Nov 18, 2024 · 2 comments
Labels
API coverage Request for missing APIs

Comments

@AlexeySAntonov
Copy link

Hey guys! Thanks for the constellation of KMP compatible firebase libraries!
I've started my migration with firebase-auth and found out that FirebaseAuthException.errorCode(s) are omitted.
It would be nice to have the errorCodes along with the error messages. Thanks!

Screenshot 2024-11-18 at 15 56 15
@AlexeySAntonov AlexeySAntonov added the API coverage Request for missing APIs label Nov 18, 2024
@AlexeySAntonov AlexeySAntonov changed the title Add [FirebaseAuthException].[errorCode] to [firebase-auth] for [iOS/Android/...] Add FirebaseAuthException.errorCode to "firebase-auth" for iOS/Android/... Nov 18, 2024
@TomerGlick
Copy link

I didn't get how to even get the exception -> using
auth.signInWithEmailAndPassword(email, password)
but how to implement those functions?

@AlexeySAntonov
Copy link
Author

AlexeySAntonov commented Nov 27, 2024

@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
  }
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
API coverage Request for missing APIs
Projects
None yet
Development

No branches or pull requests

2 participants