A
A
Alexander2020-03-28 06:44:41
JSON Web Token
Alexander, 2020-03-28 06:44:41

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()
  }
})


The problem is that if I remove the access_token from localStorage.getItem, then it does not throw me on /login, but a white screen appears. I will be glad to any advice.

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question