R
R
Ruslan Absalyamov2018-10-14 17:05:46
Vue.js
Ruslan Absalyamov, 2018-10-14 17:05:46

How to prevent an authorized user from entering the authorization page?

I am now trying to make a simple authorization page. App it outputs to non-logged in users, Home logged in. The logic that I applied there is that when you click on the button, a token is placed in vuex and redirects the authorized page to the page, respectively, if you click on the Home page, this token is erased. I'm having a problem that a logged in user can get to the App page when he should not be able to get to that page. How is this implemented?
Here is the sandbox with the implementation https://codesandbox.io/s/nrx1r643m

Answer the question

In order to leave comments, you need to log in

1 answer(s)
0
0xD34F, 2018-10-14
@rusline18

Add to App:

beforeRouteEnter(to, from, next) {
  if (store.getters.user) {
    next(false)
  } else {
    next()
  }
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question