From 49f1a98eece9160f828f27753761cf9c3db079d7 Mon Sep 17 00:00:00 2001 From: Joyelle Ndagijimana Date: Tue, 18 Mar 2025 09:25:18 +0100 Subject: [PATCH] feat: login redirect opgelost --- frontend/src/router/index.ts | 4 ++-- frontend/src/services/auth/auth-service.ts | 17 +++++++++-------- 2 files changed, 11 insertions(+), 10 deletions(-) diff --git a/frontend/src/router/index.ts b/frontend/src/router/index.ts index 1bac40ef..5f2c4624 100644 --- a/frontend/src/router/index.ts +++ b/frontend/src/router/index.ts @@ -109,9 +109,9 @@ const router = createRouter({ }); router.beforeEach(async (to, from, next) => { - // Verify if user is logged in for paths that require authentication + // Verify if user is logged in before accessing certain routes if (to.meta.requiresAuth) { - if (!authState.isLoggedIn) { + if (!authState.isLoggedIn.value) { next("/login"); } else { next(); diff --git a/frontend/src/services/auth/auth-service.ts b/frontend/src/services/auth/auth-service.ts index 53f8cb61..03ec8e54 100644 --- a/frontend/src/services/auth/auth-service.ts +++ b/frontend/src/services/auth/auth-service.ts @@ -20,6 +20,15 @@ async function getUserManagers(): Promise { }; } +/** + * Information about the current authentication state. + */ +const authState = reactive({ + user: null, + accessToken: null, + activeRole: authStorage.getActiveRole() || null, +}); + /** * Load the information about who is currently logged in from the IDP. */ @@ -35,14 +44,6 @@ async function loadUser(): Promise { return user; } -/** - * Information about the current authentication state. - */ -const authState = reactive({ - user: null, - accessToken: null, - activeRole: authStorage.getActiveRole() || null, -}); const isLoggedIn = computed(() => authState.user !== null);