From d1efcd178d656cc0c532748f03f1628e59345416 Mon Sep 17 00:00:00 2001 From: Florian Date: Sun, 9 Apr 2023 17:48:30 +0200 Subject: [PATCH] NavGuard Unauthorized users only can visit MainPage and Login --- webapp/src/router/index.ts | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/webapp/src/router/index.ts b/webapp/src/router/index.ts index 6cfc00ef8..adc2cbfa2 100644 --- a/webapp/src/router/index.ts +++ b/webapp/src/router/index.ts @@ -17,6 +17,7 @@ import NtpInfoView from '@/views/NtpInfoView.vue'; import SecurityAdminView from '@/views/SecurityAdminView.vue'; import SystemInfoView from '@/views/SystemInfoView.vue'; import { createRouter, createWebHistory } from 'vue-router'; +import { isLoggedIn } from '@/utils/authentication'; const router = createRouter({ history: createWebHistory(import.meta.env.BASE_URL), @@ -115,4 +116,15 @@ const router = createRouter({ ] }); -export default router; \ No newline at end of file +router.beforeEach((to, from, next) => { + if (to.fullPath === '/' || to.fullPath === '/login') { + next(); + } else { + if (!isLoggedIn()) { + next('/login'); + } + } + next(); +}) + +export default router;