问题
How would I be able to check in real time if the user verified his email?
My flow is like this:
- User registers
- Email is sent
- User sees "Please verify your email" notification
Now I would like to:
- setInterval -> check if email is verified
- If verified show the "Email verified" notification
For this I would need a method that fetches the user data from firebase. Usually you just use the onAuthStateChanged callback to get userdata but I need to explicitly fetch current data.
How would I do that?
回答1:
Found a way!
firebase.auth().currentUser.reload()
will fetch current user data. So all I have to do is this:
this.checkForVerifiedInterval = setInterval(() => {
firebase.auth()
.currentUser
.reload()
.then(ok => {
if (firebase.auth().currentUser.emailVerified) {
this.props.history.push("/verification-email-verified")
window.Materialize.toast("Email verified.", 3000)
clearInterval(this.checkForVerifiedInterval)
}
})
}, 1000)
来源:https://stackoverflow.com/questions/50271839/firebase-observe-email-verification-status-in-real-time