flaschengeist-frontend/src/boot/login.ts

38 lines
1.3 KiB
TypeScript
Raw Normal View History

2020-10-14 16:44:03 +00:00
import { boot } from 'quasar/wrappers';
2020-10-16 11:07:31 +00:00
import { UserStateInterface } from 'src/plugins/user/store/user';
import { RouteRecord } from 'vue-router';
2020-10-14 16:44:03 +00:00
2020-10-16 11:07:31 +00:00
export default boot(({ router, store }) => {
2020-10-16 07:38:14 +00:00
router.beforeEach((to, from, next) => {
2020-10-16 11:07:31 +00:00
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access,@typescript-eslint/ban-ts-comment
// @ts-ignore
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
const user: UserStateInterface = (<UserStateInterface>store.state).user;
2020-10-16 07:38:14 +00:00
console.log('login_boot', user);
if (
2020-10-16 11:07:31 +00:00
to.matched.some((record: RouteRecord) => {
2020-10-16 07:38:14 +00:00
// permissions is set AND has NO matching permission
return (
2020-10-16 11:07:31 +00:00
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
2020-10-16 07:38:14 +00:00
record.meta.permissions !== undefined &&
!(
2020-10-16 11:07:31 +00:00
// eslint-disable-next-line @typescript-eslint/no-unsafe-call,@typescript-eslint/no-unsafe-member-access
(
record.meta.permissions.filter((value: string) =>
user.permissions.includes(value)
).length > 0
)
2020-10-16 07:38:14 +00:00
)
);
})
) {
next({
path: '/login',
query: { redirect: to.fullPath }
});
} else {
next();
}
});
2020-10-14 16:44:03 +00:00
});