android - Firebase 9.0.2 身份验证错误代码

标签 android firebase firebase-authentication

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

最佳答案

要获取 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...
}

然后从您的 OnFailureListener 中调用此方法,如下所示:

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

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

关于android - Firebase 9.0.2 身份验证错误代码,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37962109/

相关文章:

android - 有没有办法在 Nativescript Android 应用程序中创建一个平面按钮?

php - Android Volley POST 请求 : getting GET request method on server side (php)

node.js - 如何确保在 ElasticSearch Bonsai 免费实例中使用 Firebase FlashLight 索引每个对象

javascript - firebase 身份验证/不允许操作

python - 火力地堡 "message": "PASSWORD_LOGIN_DISABLED" response when trying to authenticate

android - React Native DrawerLayoutAndroid 引用不起作用

android - Android 访问的 Servlet WebSocket

c++ - 添加 CURLOPT_TIMEOUT_MS curl 后不发送任何内容

Firebase 云调度程序功能成本

ios - Swift Firebase 不调用 observeSingleEvent 的方法