vue.js - How can I use vue-router's Navigation Guards with Vuex and VueJs 2? -


following store:

export const store = new vuex.store({   state: {     currentuser: null   },   getters,   mutations,   actions }); 

this loginuser() action:

loginuser(context, payload) {     return new promise(function(resolve, reject) {       auth.emailsignin({         email: payload.email,         password: payload.password       })       .then(function(resp){         context.commit('setcurrentuser', resp.data);         resolve();       });     });   } 

this changes currentuser state through mutation. after user logged in trying redirect him home page following method in vue component:

methods: {       loginuser(){         var = this;         this.$store.dispatch({           type: 'loginuser',           email: this.email,           password: this.password         }).then(function(){           that.$router.push('/');         });       }     } 

so guarding home route following beforeeach method:

router.beforeeach((to, from, next) => {     if (to.matched.some(record => record.meta.requireslogin)) {       auth.validatetoken()       .then(function(){         next()       })       .fail(function(){           next({             path: '/login'           })       });     } else {         next()     } })  

but happens after login goes home route redirects /login.

how can resolved?


Comments

Popular posts from this blog

javascript - Clear button on addentry page doesn't work -

c# - Selenium Authentication Popup preventing driver close or quit -

tensorflow when input_data MNIST_data , zlib.error: Error -3 while decompressing: invalid block type -