Skip to content

Instantly share code, notes, and snippets.

@andreasvirkus
Created August 17, 2018 08:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save andreasvirkus/ef757c3c02f07f9b5a608e88620e5934 to your computer and use it in GitHub Desktop.
Save andreasvirkus/ef757c3c02f07f9b5a608e88620e5934 to your computer and use it in GitHub Desktop.
router.beforeEach((to, from, next) => {
if (to.matched.some(record => record.meta.requiresAuth)) {
// this route requires auth, check if logged in if not, redirect to login page.
const isAuthenticated = false // TODO implement real auth check
if (!isAuthenticated) {
next({ path: '/login', query: { redirect: to.fullPath } })
} else {
next()
}
} else {
next()
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment