首页 > 解决方案 > task.isSuccessful() 在signInWithEmailAndPassword 中总是给出假

问题描述

我创建了一个注册用户页面和一个登录页面。用户正在注册,他们在 firebase 控制台中可见,但是当我登录时,它总是说密码无效。

以下是我的登录代码:

private void loginUser(String email, String password) {
        mAuth.signInWithEmailAndPassword(email, password)
                .addOnCompleteListener(this, new OnCompleteListener<AuthResult>() {
                    @Override
                    public void onComplete(@NonNull Task<AuthResult> task) {
                        if (task.isSuccessful()) {
                            FirebaseUser user = mAuth.getCurrentUser();
                            updateUI(user);
                        } else {
                            try {
                                throw task.getException();
                            }

                            catch (FirebaseAuthEmailException e){
                                Toast.makeText(getApplicationContext(), "Invalid Email", Toast.LENGTH_LONG).show();
                            }
                            catch (FirebaseAuthInvalidCredentialsException e) {
                                Toast.makeText(getApplicationContext(), "Invalid Password", Toast.LENGTH_LONG).show();
                            }
                            catch (FirebaseAuthException e){
                                Toast.makeText(getApplicationContext(), "Invalid Credentials", Toast.LENGTH_LONG).show();
                            }
                            catch (Exception e) {
                                e.printStackTrace();
                            }
                        }

                    }
                });
    }

    public void  updateUI(FirebaseUser user){
        if(user != null){
            Toast.makeText(this,"You Signed In successfully",Toast.LENGTH_LONG).show();
            startActivity(new Intent(this,MainActivity.class));
        }else {
            Toast.makeText(this,"You Didn't signed in",Toast.LENGTH_LONG).show();
        }
    }
}

标签: androidfirebase-authentication

解决方案


我遇到了这个问题。我犯了这些错误。

1.确保您启用从电子邮件/密码登录。

在此处输入图像描述

2.确保在你的 gradle 文件中使用最新版本的 FirebaseAuth。

implementation 'com.google.firebase:firebase-auth:19.3.1'

推荐阅读