Hi, I also struggled a lot with this one (with other frameworks alsoβ¦), but my solution with Quasar seems to work. It is the promised-based approach which I include in the my Router index.js, not in any boot file.
If changes to the user state are made, I dispatch the new state to vuex only from the Router, because if my user logs in s/he is redirected to a dashboard and if logged out redirected to another page.
export default function ({ store }) {
const router = new VueRouter({
...
})
router.beforeEach(async (to, from, next) => {
const user = await new Promise((resolve, reject) => {
firebaseAuth.onAuthStateChanged(user => {
store.dispatch('myFirebaseUserAction', user.toJSON())
resolve(user)
})
})
const requiresAuth = to.matched.some(recordedRoute => recordedRoute.meta.requiresAuth)
if (requiresAuth && !user) {
next({ path: 'login', query: { from: to.path } })
} else {
next()
}
})
return router
}