Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Successful email verification should trigger the onAuthStateChanged function #3817

Open
ethoman opened this issue Sep 21, 2020 · 10 comments
Open

Comments

@ethoman
Copy link

ethoman commented Sep 21, 2020

It would make so many people's lives easier, please consider making this change. Right now people have to make their own off brand listeners or add timers to check every couple seconds for updates - this would be such a quality of life improvement.

@google-oss-bot
Copy link
Contributor

I found a few problems with this issue:

  • I couldn't figure out how to label this issue, so I've labeled it for a human to triage. Hang tight.
  • This issue does not seem to follow the issue template. Make sure you provide all the required information.

@malcolmdeck
Copy link

Hey ethoman,

I've filed b/169070231 to track this feature request internally.

This would actually be really difficult to implement on our side in a way that doesn't waste a significant amount of resources (e.g. bandwidth) or requiring a new pathway in our system to allow clients to listen for these types of changes.

You might instead consider using Email Link Sign In, which results in users only ever having verified emails as soon as they're signed in. I'm guessing that that would solve your problem

Hope that helps!
~Malcolm

@ethoman
Copy link
Author

ethoman commented Sep 21, 2020

I appreciate the answer! I actually already use Email Link sign in. The issue is more that after email link sign in is triggered (when the user goes to their email and successfully verifies using the link sent to them), the emailVerified state in authuser is not updated. This means that the original tab the user was in when they sign up does not have updated information, though the new tab that is opened from the email does.

@AnthonyLabaere
Copy link

Hello, have you found a solution to this issue ?

@Xstyler85
Copy link

I have the same problem

@laurentpayot
Copy link

I opened #2529 for the same reason. After a successful email verification, even updateCurrentUser() call does not trigger onAuthStateChanged. I had to use onIdTokenChanged instead of onAuthStateChanged, and to use
firebase.auth().currentUser.getIdToken(true) instead of updateCurrentUser() to "manually" trigger the event.

@smac89
Copy link

smac89 commented Feb 3, 2022

I came here to report the issue as well, but it seems even the firebase team do not have a ready solution. The solution that seems to work for us is to use setInterval (taken from this stackoverflow answer), and it seems to be doing a good job of informing us when the user's email has been verified.


Edit: instead of setInterval, we opted for setIntervalAsync from https://www.npmjs.com/package/set-interval-async. This means the reload can be awaited, so that we do not simply spam every second

@jinyang1994
Copy link

+1

@Lupobb
Copy link

Lupobb commented Apr 28, 2023 via email

@antoni0dev
Copy link

antoni0dev commented Jul 5, 2023

Solution in the EmailVerificationPage where the user is sitting after being redirected from the RegisterPage:

useEffect(() => {
   const unsubscribe = firebaseAuth.onIdTokenChanged(user => {
     if (user) {
       (async () => {
         // needed because Firebase caches the user's info, and the emailVerified flag might not be updated in real-time after the user clicks the verification link in their email.
         await user.reload();

         if (user.emailVerified) {
           navigate(PATHS.accountSetup);
         }
       })();
     }
   });

   return () => {
     unsubscribe();
   };
 }, []);

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests