0

After a user signs up, they are sent a confirmation link to their email address through Firebase. If the account is not verified, the user isn't able to interact with anything on the app. Once the account is verified, the React state changes, enabling elements on the app so the user can begin interaction. Is there any way to listen to a change to the current user's auth object so that the state can change after the user clicks the confirmation link?

I tried setting up a timer like this, but it doesn't actually check currentUser.emailVerified in real time:

timer.addEventListener('secondsUpdated', () => {
  this.setState({ timer: timer.getTimeValues().seconds });

  this.forceUpdate();

  console.log(auth.currentUser.emailVerified);

  auth.onAuthStateChanged(user => {
    console.log(user.emailVerified);
  });
});

Both logs return false even after the user clicks the confirmation link. I don't want to force the user to have to refresh the page in order for the elements to be enabled, if their account is verified. Any ideas?

Ralph David Abernathy
  • 5,230
  • 11
  • 51
  • 78
  • 2
    The `emailVerified` property is not automatically updated.You will need to call `user.reload()` to get the latest data: https://firebase.google.com/docs/reference/js/firebase.User#reload Also see https://stackoverflow.com/questions/44087584/how-to-verify-email-without-the-need-of-signing-in-again-while-using-firebaseui and https://stackoverflow.com/questions/41874910/can-i-get-updated-emailverified-without-logging-out – Frank van Puffelen Jul 02 '18 at 19:17
  • This is exactly what I needed, thanks! – Ralph David Abernathy Jul 02 '18 at 22:03

0 Answers0