Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

mevn-mongodb-login-req: How to add route guard #5

Open
jsfanatik opened this issue Sep 16, 2019 · 0 comments
Open

mevn-mongodb-login-req: How to add route guard #5

jsfanatik opened this issue Sep 16, 2019 · 0 comments

Comments

@jsfanatik
Copy link

How do you add route guards to this app? I tried adding the following in the index.js:

router.beforeEach((to, from, next) => {
  const token = localStorage.usertoken
  const requiresAuth = to.matched.some(record => record.meta.requiresAuth)
  if (requiresAuth && !token) next('login')
  else if (!requiresAuth && token) next('profile')
  else next()
})
export default router

... in order to prevent the user from being logged out after refreshing the page, but to no avail. Any recommendations on how to add route guards?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant