I'm trying to determine if the user is new or an existing one. When user is registered, e-mail verification is required. When verification is successful, the user can sign in for the first time. When a new user signing in, he must fill a mandatory form with his details, so it's a completely different activity.
I've tried to use use the getAdditionalUserInfo().isNewUser() but it's always returns false. I'm not sure if the e-mail verification somehow messes it up
mAuth.signInWithEmailAndPassword(mEmail, mPassword)
.addOnCompleteListener(this, new OnCompleteListener<AuthResult>() {
@Override
public void onComplete(@NonNull Task<AuthResult> task) {
if (task.isSuccessful()) {
// Sign in success, update UI with the signed-in user's information
FirebaseUser user = mAuth.getCurrentUser();
updateUI(user);
boolean flag = task.getResult().getAdditionalUserInfo().isNewUser();
if (flag) {
Toast.makeText(EmailPasswordActivity.this, "NEW USER.",
Toast.LENGTH_SHORT).show();
} else {
Toast.makeText(EmailPasswordActivity.this, "EXISTING USER.",
Toast.LENGTH_SHORT).show();
}
} else {
// If sign in fails, display a message to the user.
Log.w(TAG, "signInWithEmail:failure", task.getException());
Toast.makeText(EmailPasswordActivity.this, "Authentication failed.",
Toast.LENGTH_SHORT).show();
updateUI(null);
}
// [START_EXCLUDE]
if (!task.isSuccessful()) {
mStatusTextView.setText(R.string.auth_failed);
}
hideProgressDialog();
// [END_EXCLUDE]
}
});