[Vuejs]-Firebase auth with vue router

0👍

I don’t know if I did it right, but as recommended in this Answer, I think this is possible in firebase.

router.beforeEach((to, from, next) => {
  auth.onAuthStateChanged(async (userFirebase) => {
    if (to.meta.requiresAuth) {
      if (userFirebase) {
        next();
      } else {
        await store.dispatch("auth/openLoginForm");
        next("/");
      }
    } else next();
  });
});

Leave a comment