Firebase 9.0.2身份验证错误代码

Arj*_*ung 5 android firebase firebase-authentication

根据旧文档firebase提供身份验证错误作为firebase错误,它提供了代码,但在新的firebase 9.0.2中,它只会异常,可以转换为FirebaseAuthException并且具有getCode但是字符串.现在我想在firebase中获得所有可能的错误.我试过但找不到任何解决方案.Ios处理错误部分并提供代码(int)错误,而不是Android.请帮忙.Thanx提前

Vic*_*ado 3

要获取 FirebaseAuth 中所有可能的错误,您可以执行以下操作:

private void handleAuthenticationException(@NonNull Exception exception) {
    if (exception instanceof FirebaseAuthUserCollisionException) {
        if (((FirebaseAuthUserCollisionException) exception).getErrorCode().equals("ERROR_ACCOUNT_EXISTS_WITH_DIFFERENT_CREDENTIAL")) {
            //do something...
        }
    }
    // Other relevant exceptions for you...
}
Run Code Online (Sandbox Code Playgroud)

并从 OnFailureListener 调用此方法,如下所示:

firebaseAuth.signInWithCredential(credential).
    .addOnSuccessListener(/*Your code here!*/)
    .addOnFailureListener(this, new OnFailureListener() {
        @Override
        public void onFailure(@NonNull Exception exception) {
            handleAuthenticationException(exception);
        }
    );
Run Code Online (Sandbox Code Playgroud)

请查看FirebaseAuthException文档以获取更多信息。