router.beforeEach(async (to, from, next) => {
if (to.matched.some(record => record.meta.requiresAuth)) {
await store.dispatch('checkSession');
if (store.getters.isAuthenticated) {
next();
} else {
next({
path: '/login',
});
}
} else {
next();
}
});
checkSession({commit, dispatch}) {
return new Promise((resolve, reject) => {
axios.get('/auth')
.then(userdata => {
commit('setUser', userdata.data)
resolve(userdata)
})
.catch((err) => {
dispatch('logout')
reject(err)
});
})
},