简体   繁体   中英

Firebase doesn't pick up email/password authentication

My code works perfectly, I get no errors, I've run the app through debug, nothing shows up. So I've already checked if I have the latest firebase dependencies and I've updated Google Play Services but for some reason My app won't register the user to Firebase.

EditText registerEmail, registerPassword;

private FirebaseAuth mAuth;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_register);

    registerEmail = (EditText) findViewById(R.id.registerEmail);
    registerPassword = (EditText) findViewById(R.id.registerPassword);

    mAuth = FirebaseAuth.getInstance();

    findViewById(R.id.registerButton).setOnClickListener(this);
}

private void registerUser() {
    String email = registerEmail.getText().toString().trim();
    String password = registerPassword.getText().toString().trim();

    if(email.isEmpty()) {
        registerEmail.setError("Email is required");
        registerEmail.requestFocus();
        return;
    }
    if(!Patterns.EMAIL_ADDRESS.matcher(email).matches()) {
        registerEmail.setError("Enter a valid email");
        registerEmail.requestFocus();
        return;
    }
    if(password.isEmpty()) {
        registerPassword.setError("Password is required");
        registerPassword.requestFocus();
        return;
    }
    if(password.length() < 8) {
        registerPassword.setError("Minimum 8 characters required");
        registerPassword.requestFocus();
        return;
    }

    mAuth.createUserWithEmailAndPassword(email, password).addOnCompleteListener(new OnCompleteListener<AuthResult>() {
        @Override
        public void onComplete(@NonNull Task<AuthResult> task) {
            if(task.isSuccessful()) {
                Toast.makeText(getApplicationContext(), "successful", Toast.LENGTH_SHORT).show();
            } else {
                Toast.makeText(getApplicationContext(), "not successful", Toast.LENGTH_SHORT).show();
            }
        }
    });

}

@Override
public void onClick(View view) {
    switch (view.getId()) {
        case R.id.registerButton:
            registerUser();
            //startActivity(new Intent(this, MainActivity.class));

            break;
        case R.id.loginTextView:

            startActivity(new Intent(this, Login.class));

            break;
    }
}

I get the "not successful" message so the issue must be in here somewhere mAuth.createUserWithEmailAndPassword() . Thank you in advance.

您遇到的错误非常容易引起误解,在网上寻找解决方案时,我发现无数人为此而苦苦挣扎,但没人提到启用Google Identity Toolkit API可以为我解决问题。

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