Reputation: 438
I am trying to create a firebase user, but my code fails, keep getting the Authentication failed message, can you please tell me why? Also, I don't know how the new firebase is connecting to my account, I used to create a Firebase object and pass my link to it, but now is different, and I can't see where it does it (It asked to login in my webbrowser and that's it, I can't find a reference for it in the code)
@Override
public void onClick(View v) {
pass.setText(pass.getText().toString().trim());
email.setText(email.getText().toString().trim());
mAuth.createUserWithEmailAndPassword(email.getText().toString(), pass.getText().toString())
.addOnCompleteListener(this, new OnCompleteListener<AuthResult>() {
@Override
public void onComplete(@NonNull Task<AuthResult> task) {
if (task.isSuccessful()) {
FirebaseUser user = mAuth.getCurrentUser();
} else {
Toast.makeText(MainActivityC.this, "Authentication failed.",
Toast.LENGTH_SHORT).show();
}
}
});
}
Upvotes: 0
Views: 1720
Reputation: 393
Check below code for your reference.. It will help you.
private FirebaseAuth mAuth;
String mUserEmail = "[email protected]";
String mPassword = "password";
mAuth.createUserWithEmailAndPassword(mUserEmail, mPassword)
.addOnCompleteListener(this, new OnCompleteListener<AuthResult>() {
@Override
public void onComplete(@NonNull Task<AuthResult> task) {
Log.d(LOG_TAG, getString(R.string.log_message_auth_successful) + " createUserWithEmail:onComplete:" + task.isSuccessful());
// if task is successful then AuthStateListener will get notified you can get user details there.
// if task is not successful show error
if (!task.isSuccessful()) {
try {
throw task.getException();
} catch (FirebaseAuthUserCollisionException e) {
// log error here
} catch (FirebaseNetworkException e) {
// log error here
} catch (Exception e) {
// log error here
}
} else {
// successfully user account created
// now the AuthStateListener runs the onAuthStateChanged callback
}
}
});
}
Upvotes: 2