mirror of
https://git.meshkee.com/cssd/cssd-back.git
synced 2026-10-13 15:31:06 +03:30
mixin role and config url
This commit is contained in:
Vendored
+9
-2
@@ -8,7 +8,7 @@
|
||||
|
||||
// Lib imports
|
||||
import Vue from 'vue'
|
||||
import VueAnalytics from 'vue-analytics'
|
||||
// import VueAnalytics from 'vue-analytics'
|
||||
import Router from 'vue-router'
|
||||
import Meta from 'vue-meta'
|
||||
import { TokenService } from '@/services'
|
||||
@@ -52,10 +52,12 @@ const router = new Router({
|
||||
|
||||
Vue.use(Meta)
|
||||
|
||||
|
||||
router.beforeEach((to, from, next) => {
|
||||
const isPublic = to.matched.some(record => record.meta.public);
|
||||
const onlyWhenLoggedOut = to.matched.some(record => record.meta.onlyWhenLoggedOut);
|
||||
const loggedIn = !!TokenService.getToken();
|
||||
const roles = to.matched.some(record => record.meta.roles);
|
||||
if (!isPublic && !loggedIn) {
|
||||
return next({
|
||||
path:'/login',
|
||||
@@ -64,10 +66,15 @@ router.beforeEach((to, from, next) => {
|
||||
}
|
||||
|
||||
// Do not allow user to visit login page or register page if they are logged in
|
||||
if (loggedIn && onlyWhenLoggedOut) {
|
||||
if (loggedIn && onlyWhenLoggedOut && policy) {
|
||||
return next('/')
|
||||
}
|
||||
|
||||
// Do not allow user to visit Pages then not access roles
|
||||
// if (roles && !$hasRole(roles)) {
|
||||
// return next('/')
|
||||
// }
|
||||
|
||||
next();
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user