[Vuejs]-Keep user session logged in when page refreshed in vue js

0👍

Since use register auth as a module, you should use store.state.auth.jwt instead of store.state.jwt

router.beforeEach((to, from, next) => {
  // to and from are both route objects. must call `next`.
  if(to.fullPath === '/dashboard-user/id/list-vendor') {
    if(!store.state.auth.jwt) {
      next('/login')
    }
  }
  if(to.fullPath === '/login') {
    if(store.state.auth.jwt) {
      next('/dashboard-user/id/list-vendor')
    }
  }
  next();
})

Leave a comment