* navbar with protected routes

feature: #3
This commit is contained in:
2023-01-03 02:26:15 +01:00
parent 23c40c5468
commit 46dd4ef361
18 changed files with 304 additions and 443 deletions

View File

@@ -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()