Firebase signInWithEmailAndPassword始终跳到其他位置

时间:2018-02-12 13:56:01

标签: java android firebase firebase-authentication

我正在尝试使用Android上的Firebase进行登录和注册页面,我可以注册用户但不能登录,我可以看到数据库中的注册用户。登录方法始终转到else部分。这是代码

    mLogin_btn.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            String email = mLoginEmail.getEditText().toString();
            String password = mLoginPassword.getEditText().toString();
            if(!TextUtils.isEmpty(email) && !TextUtils.isEmpty(password)){
                mLoginProgress.setTitle("Loggin In");
                mLoginProgress.setMessage("Please Wait!");
                mLoginProgress.setCanceledOnTouchOutside(false);
                mLoginProgress.show();

                loginUser(email, password);
            }
        }
    });

}


private void loginUser(String email, String password) {
    mAuth.signInWithEmailAndPassword(email, password).addOnCompleteListener(new OnCompleteListener<AuthResult>() {
        @Override
        public void onComplete(@NonNull Task<AuthResult> task) {

            if(task.isSuccessful()){

                mLoginProgress.dismiss();

                        Intent mainIntent = new Intent(LoginActivity.this, MainActivity.class);
                        mainIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
                        startActivity(mainIntent);
                        finish();

                    } else{
                mLoginProgress.hide();
                Toast.makeText(LoginActivity.this, "nope, skipping to else", Toast.LENGTH_SHORT).show();
            }
                }
});
}
}

1 个答案:

答案 0 :(得分:1)

试试这个:

axios.get(url)

用上面的吐司替换你的吐司,以便能够知道它为什么会出现在else语句中。

改变这个:

 else{
     mLoginProgress.hide();
    Toasty.error(getApplicationContext(), "Authentication failed: " + task.getException().getMessage(), Toast.LENGTH_SHORT).show();
        }

到此:

  String email = mLoginEmail.getEditText().toString();
  String password = mLoginPassword.getEditText().toString();