Skip to content

Instantly share code, notes, and snippets.

@blogui91
Created September 12, 2017 05:34
Show Gist options
  • Save blogui91/b528a42110231cf5cc6fd6d28e723c5b to your computer and use it in GitHub Desktop.
Save blogui91/b528a42110231cf5cc6fd6d28e723c5b to your computer and use it in GitHub Desktop.
import OAuth from 'src/oauth'
import router from 'src/router'
let oAuth = new OAuth();
router.beforeEach((to,from,next) => {
//If visiting login view but you already have logged in, you should not be able to see this view
if (to.name == 'app.login' && oAuth.isAuthenticated()) {
return next({
path: '/'
})
}
//If you are visiting '/' and you are a guest then, you must be redirected to login
if(to.meta.requiresAuth && oAuth.guest()){
return next({
path: '/login',
query: {
redirect: to.fullPath
}
})
}
return next()
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment