[英]Firebase Email + Password login event not firing
I am having a problem with my Login and Register events in Firebase. 我在Firebase中的登录和注册事件遇到问题。 The code skips the entire event. 该代码将跳过整个事件。
public class LoginFragment extends Fragment {
String TAG = "LOGIN";
TextView tvLoginError;
EditText etUsername, etPassword;
Button btnLogin;
public LoginFragment() {}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View rootView = inflater.inflate(R.layout.login, container, false);
setupTools(rootView);
return rootView;
}
private void setupTools(View rootView){
tvLoginError = (TextView) rootView.findViewById(R.id.tvLoginError);
etUsername = (EditText) rootView.findViewById(R.id.etUsername);
etPassword = (EditText) rootView.findViewById(R.id.etPassword);
btnLogin = (Button) rootView.findViewById(R.id.btnLogin);
btnLogin.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
final String username = etUsername.getText().toString();
final String password = etPassword.getText().toString();
// login
Authenticate.mAuth.signInWithEmailAndPassword(username, password).addOnCompleteListener(getActivity(), new OnCompleteListener<AuthResult>() {
@Override
public void onComplete(@NonNull Task<AuthResult> task) {
Log.d(TAG, "signInWithEmail:onComplete:" + task.isSuccessful());
// If sign in fails, display a message to the user. If sign in succeeds the auth state listener will be notified and logic to handle the signed in user can be handled in the listener.
if (!task.isSuccessful()) {
Log.w(TAG, "signInWithEmail", task.getException());
tvLoginError.setText("Login failed - " + task.getException().getMessage().toString());
}
}
});
}
});
}
}
Authenticate.mAuth is not null. Authenticate.mAuth不为null。 Username and password are set. 设置用户名和密码。
There are no errors, it just skips the onComplete
function in signInWithEmailAndPassword
completely. 没有错误,它只是完全跳过signInWithEmailAndPassword
的onComplete
函数。 My AuthStateListener
event in Authentication
gets fired onResume
in Authentication
(the user is logged out as i am unable to register or login). 我AuthStateListener
事件Authentication
被炒鱿鱼onResume
在Authentication
(用户登录了,因为我无法注册或登录)。
I have the internet permission in my manifest too. 我的清单中也有互联网许可。
Turns out there was nothing wrong with my code, but my google_services.json file was incorrect (no idea why, i got this from Firebase / Google after i setup Firebase Auth). 事实证明,我的代码没有任何问题,但是我的google_services.json文件不正确(不知道为什么,我在设置Firebase身份验证后从Firebase / Google获得了此信息)。 I ended up refreshing it by changing a setting in Firebase, then reverting that setting back and downloaded google_services.json again. 最后,我通过更改Firebase中的设置来刷新它,然后恢复该设置并再次下载google_services.json。 That worked.. Strange. 那个有用..奇怪。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.