Firebase: Observe email verification status in real time

…衆ロ難τιáo~ 提交于 2019-12-11 02:47:13

问题


How would I be able to check in real time if the user verified his email?

My flow is like this:

  1. User registers
  2. Email is sent
  3. User sees "Please verify your email" notification

Now I would like to:

  1. setInterval -> check if email is verified
  2. 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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!