Angularfire: Watch the status of email verification in real time of firebase user in auth

Created on 8 Nov 2017  路  10Comments  路  Source: angular/angularfire

Version info

Angular: 4.4.6

Firebase: 4.6.0

AngularFire: 5.0.0-rc.3

Watch the status of email verification in real time of firebase user in auth

I've already looked everywhere on how to do to see the verification status of the user's email in real time and I can not find how to do it.
I already tried with firebase.auth (). OnAuthStateChanged and with the observable firebase.authState. And if the user validates his mail, with no method I can see the change in real time. Moreover, not even the firebase object has any way of reloading the firebase.user, I have to reload everything to update the state of emailVerified.

How could I see in real time the change of user verification with the current instance of firebase?

Most helpful comment

Why was this closed? What would be the recommended way of doing this?

All 10 comments

https://www.youtube.com/watch?v=2ZDeT5hLIBQ
I recommend you to watch this vid, It's one of the best ones I've seen on Youtube.

That's right brother, I could not either, I hope those of angular firebase help us.

That would be perfect, so that the user can not enter until verified his mail there, and once verified, in real time to detect the verification and redirect the user inside the platform.

Why was this closed? What would be the recommended way of doing this?

see #1464

This can be solved with getIdToken and onIdTokenChanged with the js sdk.

What's the solution here? 1464 doesn't even address this issue.

I implemented this by fetching current userinfo and checking if user.isEmailVerified() in an interval

Thanks Brian. Just in case someone uses this for react native, I added something extra for reloading the auth.currentUser details:
auth.currentUser.reload().then(() => {});

For me it seems to work only when combining both auth.updateCurrentUser(user) and user.reload().

Here's a promise which resolves when the email has been verified:

public async refreshUserUntilEmailVerified(interval = 1000) {
    await this.auth.user
        .pipe(
            auditTime(interval),
            tap(user => {
                this.auth.updateCurrentUser(user);
                user?.reload();
            }),
            filter(user => !!user?.emailVerified),
            take(1),
        ).toPromise();
}
Was this page helpful?
0 / 5 - 0 ratings