Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

FirebaseUser isEmailVerified is always returning false even after verifying email

I have a static AuthProvider class that centralizes all authentication.

I have the following registration code.

  AuthResult newUser = await auth.createUserWithEmailAndPassword(
      email: email, password: password);
  if (newUser == null) {
    print(
        'AuthProvider: empty user is returned from createUserWithEmailAndPassword');
    return false;
  }
  await newUser.user.sendEmailVerification();
  return true;

After signing up on the app, I received a verification email, so I clicked on it. When I try to sign in next time, isEmailVerified is returning false. After some research, I think I am supposed to reload the user object as follows:

FirebaseUser user = await auth.currentUser();
await user.reload();
user = await auth.currentUser();

print('${user.isEmailVerified}');

Unfortunately, isEmailVerified is still returning false. Does anyone have any idea why this is happening?

like image 948
yangrm Avatar asked Sep 20 '25 00:09

yangrm


1 Answers

The isEmailVerified isn't updated until the next time an ID token is generated for the user.

You have a few options to accomplish this:

  1. The ID token is auto-refreshed every 55 minutes, so you can wait for it to refresh.
  2. You can sign the user out, and tell them to sign them back in again, which will also generate a new ID token with the updated isEmailVerified value.
  3. You can call getIdToken(true) or reload() on the user, which forces it to refresh the ID token and thus get the updated isEmailVerified value.
like image 51
Frank van Puffelen Avatar answered Sep 21 '25 14:09

Frank van Puffelen