Is there something to auto update this code in vue?

后端 未结 2 1657
情书的邮戳
情书的邮戳 2021-01-27 18:18

I got this button in the navigator that shows up when a user is logged in and when the user logs out the button is gone. But now i need to refresh my page before the button remo

2条回答
  •  深忆病人
    2021-01-27 19:11

    You'll want to use an onAuthStateChanged listener instead of the currentUser:

    mounted() {
      firebase.auth().onAuthStateChanged((user) => {
        if(user) {
          this.ingelogd = true;
        }
      });
    },
    

    The onAuthStateChanged listener gets called each time the sign-in state changes, which ensures your ingelogd always reflects this state.

    For more on this, see the first snippet in the Firebase documentation on getting the currently signed in user.

提交回复
热议问题