本文介绍了Android上的Firebase:如何检查Firebase身份验证失败的原因?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用Android上的 Firebase 和 Firebase身份验证功能。



我尝试 FirebaseAuth.signInWithEmailAndPassword ,万一它失败,我想知道为什么signIn进程失败?

signInWithEmailAndPassword 方法具有 addOnFailureListener API。
我可以在 onFailure 中捕获 Exception (也许 FirebaseAuthException code> callback方法。

pre $ auth.signInWithEmailAndPassword(loginRequest.id,loginRequest.password)
.addOnFailureListener (新的OnFailureListener(){
@Override
public void onFailure(@NonNull Exception e){
if(e instanceof FirebaseAuthException){
((FirebaseAuthException)e).getErrorCode ));
}
}
});

我想知道SignIn进程失败的原因。在 onFailure 。



我认为可以这样做:


  1. e 实例类型check(e instanceOf FirebaseAuthInvalidUserException 或 FirebaseAuthInvalidCredentialsException 或,,,)

  2. e.getErrorCode()

我不想输入支票(很脏)。
我更喜欢上面选择的方式。但是我找不到 e.getErrorCode()返回值集合的定义。
例如 ERROR_INVALID_EMAIL , ERROR_ACCOUNT_EXISTS_WITH_DIFFERENT_CREDENTIAL 等
(它们在哪里定义? p>

请告诉我哪个是检查 Firebase身份验证失败的原因的最佳方法。



谢谢。

解决方案

我在Firebase库中发现了一些类似于失败消息的代码迄今为止看到。但还没有尝试。您可以尝试一下。

 (ERROR_INVALID_CUSTOM_TOKEN,自定义令牌格式不正确,请检查文档。 )); 
(ERROR_CUSTOM_TOKEN_MISMATCH,自定义令牌对应于不同的受众。));
(ERROR_INVALID_CREDENTIAL,提供的验证凭据格式错误或已过期。));
(ERROR_INVALID_EMAIL,电子邮件地址格式不正确));
(ERROR_WRONG_PASSWORD,密码无效或用户没有密码));
(ERROR_USER_MISMATCH,提供的凭证不对应于以前登录的用户。));
(ERROR_REQUIRES_RECENT_LOGIN,这个操作是敏感的,需要最近的认证,再次登录后再重试这个请求。));
(ERROR_ACCOUNT_EXISTS_WITH_DIFFERENT_CREDENTIAL,一个账号已经有了相同的电子邮件地址,但登录凭据不同,请使用与此电子邮件地址相关的提供商登录。
(ERROR_EMAIL_ALREADY_IN_USE,电子邮件地址已被另一个帐户使用));
(ERROR_CREDENTIAL_ALREADY_IN_USE,这个证书已经与一个不同的用户帐户相关联。));
(ERROR_USER_DISABLED,用户帐户已被管理员禁用));
(ERROR_USER_TOKEN_EXPIRED,用户的凭证不再有效,用户必须重新登录));
(ERROR_USER_NOT_FOUND,没有对应于这个标识符的用户记录,用户可能已经被删除了。
(ERROR_INVALID_USER_TOKEN,用户的凭证不再有效,用户必须再次登录));
(ERROR_OPERATION_NOT_ALLOWED,这个操作是不允许的,你必须在控制台中启用这个服务。));
(ERROR_WEAK_PASSWORD,给定的密码无效。));


I use Firebase on Android and Firebase Auth functions.

I try FirebaseAuth.signInWithEmailAndPassword and in case it fails I want to know "Why the signIn process failed?"

The signInWithEmailAndPassword method has addOnFailureListener API.And I can catch the Exception(maybe FirebaseAuthException) in onFailure callback method.

auth.signInWithEmailAndPassword(loginRequest.id, loginRequest.password)
  .addOnFailureListener(new OnFailureListener() {
    @Override
    public void onFailure(@NonNull Exception e) {
      if (e instanceof FirebaseAuthException) {
        ((FirebaseAuthException) e).getErrorCode());
      }
    }
  });

I want to know why the SignIn process failed. in onFailure.

I think it could be done as follows:

  1. e instance type check(e instanceOf FirebaseAuthInvalidUserException or FirebaseAuthInvalidCredentialsException or ,,,)
  2. e.getErrorCode()

I do not want to type checks(it's dirty).
I prefer the way in choice 2. above. But I could not find the definition of e.getErrorCode() return values collection.e.g ERROR_INVALID_EMAIL, ERROR_ACCOUNT_EXISTS_WITH_DIFFERENT_CREDENTIAL, etc.(Where are they defined?)

Please tell me which is the best way to check the reason for Firebase auth failed.

Thanks.

解决方案

I found some codes inside Firebase library which is similar to the failure messages have seen so far. But havent tried yet. You can give it a try.

    ("ERROR_INVALID_CUSTOM_TOKEN", "The custom token format is incorrect. Please check the documentation."));
    ("ERROR_CUSTOM_TOKEN_MISMATCH", "The custom token corresponds to a different audience."));
    ("ERROR_INVALID_CREDENTIAL", "The supplied auth credential is malformed or has expired."));
    ("ERROR_INVALID_EMAIL", "The email address is badly formatted."));
    ("ERROR_WRONG_PASSWORD", "The password is invalid or the user does not have a password."));
    ("ERROR_USER_MISMATCH", "The supplied credentials do not correspond to the previously signed in user."));
    ("ERROR_REQUIRES_RECENT_LOGIN", "This operation is sensitive and requires recent authentication. Log in again before retrying this request."));
    ("ERROR_ACCOUNT_EXISTS_WITH_DIFFERENT_CREDENTIAL", "An account already exists with the same email address but different sign-in credentials. Sign in using a provider associated with this email address."));
    ("ERROR_EMAIL_ALREADY_IN_USE", "The email address is already in use by another account."));
    ("ERROR_CREDENTIAL_ALREADY_IN_USE", "This credential is already associated with a different user account."));
    ("ERROR_USER_DISABLED", "The user account has been disabled by an administrator."));
    ("ERROR_USER_TOKEN_EXPIRED", "The user\'s credential is no longer valid. The user must sign in again."));
    ("ERROR_USER_NOT_FOUND", "There is no user record corresponding to this identifier. The user may have been deleted."));
    ("ERROR_INVALID_USER_TOKEN", "The user\'s credential is no longer valid. The user must sign in again."));
    ("ERROR_OPERATION_NOT_ALLOWED", "This operation is not allowed. You must enable this service in the console."));
    ("ERROR_WEAK_PASSWORD", "The given password is invalid."));

这篇关于Android上的Firebase:如何检查Firebase身份验证失败的原因?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-14 01:46