Answer the question
In order to leave comments, you need to log in
Authorization check in vuejs?
Hello, I wrote this code:
router.beforeEach((to, from, next) => {
if (to.matched.some(record => record.meta.requiresAuth)) {
if (Store.getters.isLoggedIn) {
next()
return
}
next({ name: 'Feed' })
} else if (to.matched.some(record => record.meta.guest)) {
if (localStorage.getItem('access_token') == null) {
next()
} else {
next({ name: 'Feed' })
}
} else {
next()
}
})
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question