简体   繁体   中英

Firebase Email + Password login event not firing

I am having a problem with my Login and Register events in 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. Username and password are set.

There are no errors, it just skips the onComplete function in signInWithEmailAndPassword completely. My AuthStateListener event in Authentication gets fired onResume in Authentication (the user is logged out as i am unable to register or login).

I have the internet permission in my manifest too.

You need to provide some more details in your question and you can try to follow this tutorial. It demonstrate how to build Firebase Authentication demo app using the new Firebase Email & Password authentication..

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). I ended up refreshing it by changing a setting in Firebase, then reverting that setting back and downloaded google_services.json again. That worked.. Strange.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM