Skip to content

Instantly share code, notes, and snippets.

@apavel3458
Created February 28, 2020 03:44
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 apavel3458/c3b24daf037d0650df137a8894b6e8e0 to your computer and use it in GitHub Desktop.
Save apavel3458/c3b24daf037d0650df137a8894b6e8e0 to your computer and use it in GitHub Desktop.
// import { notAuthenticated } from './axios'
import { Notify } from 'quasar'
// export default ({ router, store, Vue }) => {
// router.beforeEach((to, from, next) => {
// // Now you need to add your authentication logic here, like calling an API endpoint
// alert('beforeach')
// })
// }
let routerInstance = void 0
// export default async ({ router }) => {
// // something to do
// routerInstance = router
// }
export default ({ router, store, Vue }) => {
router.beforeEach((to, from, next) => {
const adminRequired = to.matched.some(record => record.meta.admin)
const authenticatedRequired = to.matched.some(record => record.meta.private)
if (authenticatedRequired && !store.getters['security/isAuthenticated']) {
// this route requires auth, checked if logged in
Notify.create({ color: 'negative', message: 'You must log in to access this page', icon: 'report_problem' })
store.dispatch('security/setRedirect', to.fullPath)
return next({
name: 'login'
// query: { redirect: to.fullPath }
})
}
if (adminRequired && !store.getters['security/isAdmin']) {
return next('/dashboard')
}
next()
})
routerInstance = router
}
export { routerInstance }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment