Open ethoman opened 4 years ago
I found a few problems with this issue:
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
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.
Hello, have you found a solution to this issue ?
I have the same problem
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.
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
+1
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();
};
}, []);
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.