feat: login redirect opgelost

This commit is contained in:
Joyelle Ndagijimana 2025-03-18 09:25:18 +01:00
parent 37ecad30ea
commit 49f1a98eec
2 changed files with 11 additions and 10 deletions

View file

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

View file

@ -20,6 +20,15 @@ async function getUserManagers(): Promise<UserManagersForRoles> {
};
}
/**
* Information about the current authentication state.
*/
const authState = reactive<AuthState>({
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<User | null> {
return user;
}
/**
* Information about the current authentication state.
*/
const authState = reactive<AuthState>({
user: null,
accessToken: null,
activeRole: authStorage.getActiveRole() || null,
});
const isLoggedIn = computed(() => authState.user !== null);