0

I need to get the current Firebase authenticated user on each component load in Vue. At the moment I have this in each beforeMount():

firebase.auth().onAuthStateChanged((user) => {
  if (user) {
    // User is signed in, see docs for a list of available properties
    // https://firebase.google.com/docs/reference/js/firebase.User
  } else {
    // User is signed out
    // ...
  }
})

I tried simplifying this to:

var user = firebase.auth().currentUser

It didn't work. Why doesn't it work, when the auth state hasn't changed? I'm confused by this. Is the first method the best way to accomplish this?

Frank van Puffelen
  • 565,676
  • 79
  • 828
  • 807
Joseph
  • 691
  • 4
  • 18

0 Answers0