import { boot } from 'quasar/wrappers'; import { RouteRecord } from 'vue-router'; import { Store } from 'vuex' import { StateInterface } from 'src/store'; export default boot>(({ router, store }) => { router.beforeEach((to, from, next) => { store.dispatch('user/loadFromLocalStorage').then(() => { const user: User = store.getters['user/user']; let permissions: string[] = []; user.roles.forEach(role => { permissions = permissions.concat(role.permissions) }); if ( to.matched.some((record: RouteRecord) => { // permissions is set AND has NO matching permission return ( "permissions" in record.meta && ( record.meta.permissions.filter((value: string) => permissions.includes(value) ).length == 0 ) ); }) ) { next({ path: '/login', query: { redirect: to.fullPath } }); } else { next(); } }).catch(error => { console.exception(error); }); }) });