How to observe firebase.auth().currentUser.displayName and other attributes for changes?

前端 未结 2 1758
独厮守ぢ
独厮守ぢ 2021-01-18 01:11

I am using firebase auth and when users change their profile, such as their displayName, photoURL, or email etc. the onAuthState

2条回答
  •  终归单人心
    2021-01-18 01:58

    I get the same problem for me, I was using with react and want to see a component who changed from Send verification Email to Email Verified. What I've done it's create a function who wrap the reload method on the user instance. This one is a promise, so when the promise fulfilled I now call the firebase.auth().currentUser function who get now update cause of the reload. I match all that with some component lifecycle etc.

    const user = firebase.auth().currentUser;
    user.reload().then(() => {
      const refreshUser = firebase.auth().currentUser;
      // do your stuff here
    })
    

    The docs for the reload are there. https://firebase.google.com/docs/reference/js/firebase.User#reload

    Hope that can help :)

提交回复
热议问题