@@ -1,6 +1,7 @@
|
||||
import { createRouter, createWebHistory } from 'vue-router'
|
||||
import HomeView from '../views/HomeView.vue'
|
||||
import AuthHelper from '../authentication/AuthHelper'
|
||||
import store from '../store/index'
|
||||
import { getKeycloak, keycloakSetup } from '../authentication/AuthHelper'
|
||||
|
||||
const router = createRouter({
|
||||
history: createWebHistory(import.meta.env.BASE_URL),
|
||||
@@ -13,13 +14,59 @@ const router = createRouter({
|
||||
requiresAuth: false
|
||||
}
|
||||
},
|
||||
{
|
||||
path: '/contracts',
|
||||
name: 'contracts',
|
||||
// this page is lazy-loaded when the route is visited.
|
||||
component: () => import('../views/ContractsView.vue'),
|
||||
meta: {
|
||||
requiresAuth: true
|
||||
}
|
||||
},
|
||||
{
|
||||
path: '/support',
|
||||
name: 'support',
|
||||
// this page is lazy-loaded when the route is visited.
|
||||
component: () => import('../views/SupportView.vue'),
|
||||
meta: {
|
||||
requiresAuth: true
|
||||
}
|
||||
},
|
||||
{
|
||||
path: '/support',
|
||||
name: 'support',
|
||||
// this page is lazy-loaded when the route is visited.
|
||||
component: () => import('../views/AdministrationView.vue'),
|
||||
meta: {
|
||||
requiresAuth: true,
|
||||
requiresAdmin: true
|
||||
}
|
||||
},
|
||||
{
|
||||
path: '/arbeiten',
|
||||
name: 'arbeiten',
|
||||
// this page is lazy-loaded when the route is visited.
|
||||
component: () => import('../views/ArbeitenView.vue'),
|
||||
meta: {
|
||||
requiresAuth: false
|
||||
}
|
||||
},
|
||||
{
|
||||
path: '/contact',
|
||||
name: 'contact',
|
||||
// this page is lazy-loaded when the route is visited.
|
||||
component: () => import('../views/ContactView.vue'),
|
||||
meta: {
|
||||
requiresAuth: false
|
||||
}
|
||||
},
|
||||
{
|
||||
path: '/about',
|
||||
name: 'about',
|
||||
// this page is lazy-loaded when the route is visited.
|
||||
component: () => import('../views/AboutView.vue'),
|
||||
meta: {
|
||||
requiresAuth: true
|
||||
requiresAuth: false
|
||||
}
|
||||
},
|
||||
{
|
||||
@@ -43,10 +90,11 @@ const router = createRouter({
|
||||
|
||||
router.beforeEach(async (to, from, next) => {
|
||||
if (to.meta.requiresAuth === true) {
|
||||
if (AuthHelper.getKeycloak() === null) {
|
||||
await AuthHelper.setup()
|
||||
if (getKeycloak() === null) {
|
||||
await keycloakSetup()
|
||||
store.commit('initKeycloak', getKeycloak())
|
||||
}
|
||||
if (!AuthHelper.getKeycloak().authenticated) {
|
||||
if (!getKeycloak().authenticated) {
|
||||
next('/forbidden')
|
||||
}
|
||||
next()
|
||||
|
||||
Reference in New Issue
Block a user