This is a very short snippet with a hack for dealing with when a user actions a verification email from Firebase. The example is from a webapp client, but it applies to a common problem that is a gap in the auth workflow.
When someone registers using the email/password flow in firebase, there’s a handy extra step to deal with verification of an email address.
- A user registers, and is entered into the auth database, but marked as unverified
- He gets an email with a link to click which verifies him
- The auth database gets marked as verified
In a Firebase auth enabled client, changes in authenticated user is generally handled with the onAuthStateChanged event.
There’s also a less useful event that detects when an auth token changes.
However, a change in verification status doesn’t trigger these events, so if your app triggers the method to send an email verification, you won’t know when the user verifies as for some baffling reason, the change in that auth state doesn’t fire these change events.
And the recursive polling is done here
Another issue is that an unverified user may logout, and login again without triggering an email verify action, and use an email verification link sent in a previous session.
We need to also set this polling up on change of user if this happens
And that’s the hack. Ping me if anybody has a better idea (especially the Firebase team if they happen to fix this little annoyance)