Created
September 12, 2017 05:34
-
-
Save blogui91/b528a42110231cf5cc6fd6d28e723c5b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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