From 774adb6688da73d2ac15ae714884197e17f83d8d Mon Sep 17 00:00:00 2001 From: Tibo De Peuter Date: Thu, 13 Mar 2025 01:21:38 +0100 Subject: [PATCH] fix: .js toevoegen aan imports --- backend/src/middleware/auth/auth.ts | 2 +- frontend/src/services/auth/auth-service.ts | 23 +++++++++++----------- 2 files changed, 13 insertions(+), 12 deletions(-) diff --git a/backend/src/middleware/auth/auth.ts b/backend/src/middleware/auth/auth.ts index ca64b3b3..5ff5a53c 100644 --- a/backend/src/middleware/auth/auth.ts +++ b/backend/src/middleware/auth/auth.ts @@ -6,7 +6,7 @@ import * as express from 'express'; import * as jwt from 'jsonwebtoken'; import { AuthenticatedRequest } from './authenticated-request.js'; import { AuthenticationInfo } from './authentication-info.js'; -import { ForbiddenException, UnauthorizedException } from '../../exceptions'; +import { ForbiddenException, UnauthorizedException } from '../../exceptions.js'; const JWKS_CACHE = true; const JWKS_RATE_LIMIT = true; diff --git a/frontend/src/services/auth/auth-service.ts b/frontend/src/services/auth/auth-service.ts index 61032170..53f8cb61 100644 --- a/frontend/src/services/auth/auth-service.ts +++ b/frontend/src/services/auth/auth-service.ts @@ -12,12 +12,13 @@ import apiClient from "@/services/api-client.ts"; import router from "@/router"; import type { AxiosError } from "axios"; -const authConfig = await loadAuthConfig(); - -const userManagers: UserManagersForRoles = { - student: new UserManager(authConfig.student), - teacher: new UserManager(authConfig.teacher), -}; +async function getUserManagers(): Promise { + const authConfig = await loadAuthConfig(); + return { + student: new UserManager(authConfig.student), + teacher: new UserManager(authConfig.teacher), + }; +} /** * Load the information about who is currently logged in from the IDP. @@ -27,7 +28,7 @@ async function loadUser(): Promise { if (!activeRole) { return null; } - const user = await userManagers[activeRole].getUser(); + const user = await (await getUserManagers())[activeRole].getUser(); authState.user = user; authState.accessToken = user?.access_token || null; authState.activeRole = activeRole || null; @@ -59,7 +60,7 @@ async function initiateLogin() { async function loginAs(role: Role): Promise { // Storing it in local storage so that it won't be lost when redirecting outside of the app. authStorage.setActiveRole(role); - await userManagers[role].signinRedirect(); + await (await getUserManagers())[role].signinRedirect(); } /** @@ -70,7 +71,7 @@ async function handleLoginCallback(): Promise { if (!activeRole) { throw new Error("Login callback received, but the user is not logging in!"); } - authState.user = (await userManagers[activeRole].signinCallback()) || null; + authState.user = (await (await getUserManagers())[activeRole].signinCallback()) || null; } /** @@ -84,7 +85,7 @@ async function renewToken() { return; } try { - return await userManagers[activeRole].signinSilent(); + return await (await getUserManagers())[activeRole].signinSilent(); } catch (error) { console.log("Can't renew the token:"); console.log(error); @@ -98,7 +99,7 @@ async function renewToken() { async function logout(): Promise { const activeRole = authStorage.getActiveRole(); if (activeRole) { - await userManagers[activeRole].signoutRedirect(); + await (await getUserManagers())[activeRole].signoutRedirect(); authStorage.deleteActiveRole(); } }