[Vuejs]-Firebase logouton page refresh in vue app

-1👍

I changed routeguard to watch for auth initialization and then check for currentUser.

router.beforeEach((to, from, next) => {
    auth.onAuthStateChanged(function(user) {
        const requiresAuth = to.matched.some(record => record.meta.requiresAuth);
        if (!requiresAuth) {
            next()
        } else if (requiresAuth && user) {
            next()
        } else {
            next("/signin");
        }
    });
});

Leave a comment