38 lines
1.0 KiB
TypeScript
38 lines
1.0 KiB
TypeScript
import { boot } from 'quasar/wrappers';
|
|
import { RouteRecord } from 'vue-router';
|
|
import { Store } from 'vuex'
|
|
import { StateInterface } from 'src/store';
|
|
|
|
export default boot<Store<StateInterface>>(({ router, store }) => {
|
|
router.beforeEach((to, from, next) => {
|
|
store.dispatch('user/loadFromLocalStorage').then(() => {
|
|
const permissions = store.getters['user/permissions'];
|
|
console.log('login_boot', 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);
|
|
});
|
|
})
|
|
});
|