-
-
Save apavel3458/c3b24daf037d0650df137a8894b6e8e0 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 { 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