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?