Reputation: 3
I try to write my messenger. I need to register new user in FirebaseAuth. For that, i need to get "true" in isEmailVerified()
. My programm sends emailverification to current user. It means that, current user is not null, but in next line i call isEmailVerified()
and it returns false, even when email is verified.
mAuth.createUserWithEmailAndPassword(edEmail.getText().toString(), edPassword.getText().toString())
.addOnCompleteListener(new OnCompleteListener<AuthResult>() {
@Override
public void onComplete(@NonNull Task<AuthResult> task) {
if (task.isSuccessful()) {
FirebaseUser currentUser = mAuth.getCurrentUser();
if (currentUser != null) {
sendEmailVerify(currentUser);
if (currentUser.isEmailVerified()) {
StartActivity(MainActivity.class);
}
}else{
Toast.makeText(RegActivity.this, "Error", Toast.LENGTH_SHORT).show();
}
} else {
Toast.makeText(RegActivity.this, "email or password error", Toast.LENGTH_SHORT).show();
}
}
});
private void sendEmailVerify(FirebaseUser currentUser) {
currentUser.sendEmailVerification().addOnCompleteListener(new OnCompleteListener<Void>() {
@Override
public void onComplete(@NonNull Task<Void> task) {
if (task.isSuccessful()) {
} else {
}
}
});
}
public void StartActivity(Class activity) {
Intent intent = new Intent(RegActivity.this, activity);
startActivity(intent);
RegActivity.this.finish();
}
My program must wait until the moment your email will be verified.
Upvotes: 0
Views: 68
Reputation: 599686
Sending a verification email does not immediately set the email address as verified on a user profile. After all, the mail could bounce or it could be sent to a mailbox that the user doesn't own. Only once the user clicks the link in the email, does Firebase mark their email address as verified.
Since this click on the link and subsequent web page load happens outside of your application, your application code also doesn't get notified when it happens. Instead, the profile in your application only gets the updated information when:
reload()
on the current user.That last option gives you the most flexibility, as you can determine in your application code when to force this refresh. Common ways to go about this:
For the best experience, you may considering multiple or all of these.
Upvotes: 2