Reputation: 87
I have the following piece of code:
firebaseAuth.createUserWithEmailAndPassword(email, senha)
.addOnCompleteListener(CadastroActivity.this, new OnCompleteListener<AuthResult>() {
@Override
public void onComplete(@NonNull Task<AuthResult> task) {
if(task.isSuccessful()) {
Toast.makeText(getApplicationContext(), "Success", Toast.LENGTH_SHORT).show();
Log.i("SuccessInCreateUser", task.getException().toString());
}
else{
Toast.makeText(getApplicationContext(), "Error", Toast.LENGTH_SHORT).show();
Log.i("ErrorInCreateUser", task.getException().toString());
}
}
});
When I execute the app, the user IS created as expected but it never go through the onComplete method, am I doing something wrong?
Upvotes: 1
Views: 1115
Reputation: 2872
I think there is no need to put task.isSuccesful() as it's already onComplete() callback. Would ask you to try following snippet:
firebaseAuth.createUserWithEmailAndPassword(email, senha)
.addOnCompleteListener(CadastroActivity.this, new OnCompleteListener<AuthResult>() {
@Override
public void onComplete(@NonNull Task<AuthResult> task) {
Toast.makeText(getApplicationContext(), "Success", Toast.LENGTH_SHORT).show();
Log.d("SuccessInCreateUser", "No exception");
if (!task.isSuccessful()) {
Log.w(TAG, "onComplete: Failed=" + task.getException().getMessage());
//Catch specific exception here like this. Below is the example of password less than 6 char - weak password exception catch
if (task.getException() instanceof FirebaseAuthWeakPasswordException) {
Toast.makeText(getApplicationContext(), "Weak Password", Toast.LENGTH_SHORT).show();
}
}
});
Do let me know if it changes anything for you.
Upvotes: 1