fix: .js toevoegen aan imports

This commit is contained in:
Tibo De Peuter 2025-03-13 01:21:38 +01:00
parent 7b317b28d1
commit 774adb6688
Signed by: tdpeuter
GPG key ID: 38297DE43F75FFE2
2 changed files with 13 additions and 12 deletions

View file

@ -6,7 +6,7 @@ import * as express from 'express';
import * as jwt from 'jsonwebtoken'; import * as jwt from 'jsonwebtoken';
import { AuthenticatedRequest } from './authenticated-request.js'; import { AuthenticatedRequest } from './authenticated-request.js';
import { AuthenticationInfo } from './authentication-info.js'; import { AuthenticationInfo } from './authentication-info.js';
import { ForbiddenException, UnauthorizedException } from '../../exceptions'; import { ForbiddenException, UnauthorizedException } from '../../exceptions.js';
const JWKS_CACHE = true; const JWKS_CACHE = true;
const JWKS_RATE_LIMIT = true; const JWKS_RATE_LIMIT = true;

View file

@ -12,12 +12,13 @@ import apiClient from "@/services/api-client.ts";
import router from "@/router"; import router from "@/router";
import type { AxiosError } from "axios"; import type { AxiosError } from "axios";
const authConfig = await loadAuthConfig(); async function getUserManagers(): Promise<UserManagersForRoles> {
const authConfig = await loadAuthConfig();
const userManagers: UserManagersForRoles = { return {
student: new UserManager(authConfig.student), student: new UserManager(authConfig.student),
teacher: new UserManager(authConfig.teacher), teacher: new UserManager(authConfig.teacher),
}; };
}
/** /**
* Load the information about who is currently logged in from the IDP. * Load the information about who is currently logged in from the IDP.
@ -27,7 +28,7 @@ async function loadUser(): Promise<User | null> {
if (!activeRole) { if (!activeRole) {
return null; return null;
} }
const user = await userManagers[activeRole].getUser(); const user = await (await getUserManagers())[activeRole].getUser();
authState.user = user; authState.user = user;
authState.accessToken = user?.access_token || null; authState.accessToken = user?.access_token || null;
authState.activeRole = activeRole || null; authState.activeRole = activeRole || null;
@ -59,7 +60,7 @@ async function initiateLogin() {
async function loginAs(role: Role): Promise<void> { async function loginAs(role: Role): Promise<void> {
// Storing it in local storage so that it won't be lost when redirecting outside of the app. // Storing it in local storage so that it won't be lost when redirecting outside of the app.
authStorage.setActiveRole(role); authStorage.setActiveRole(role);
await userManagers[role].signinRedirect(); await (await getUserManagers())[role].signinRedirect();
} }
/** /**
@ -70,7 +71,7 @@ async function handleLoginCallback(): Promise<void> {
if (!activeRole) { if (!activeRole) {
throw new Error("Login callback received, but the user is not logging in!"); 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; return;
} }
try { try {
return await userManagers[activeRole].signinSilent(); return await (await getUserManagers())[activeRole].signinSilent();
} catch (error) { } catch (error) {
console.log("Can't renew the token:"); console.log("Can't renew the token:");
console.log(error); console.log(error);
@ -98,7 +99,7 @@ async function renewToken() {
async function logout(): Promise<void> { async function logout(): Promise<void> {
const activeRole = authStorage.getActiveRole(); const activeRole = authStorage.getActiveRole();
if (activeRole) { if (activeRole) {
await userManagers[activeRole].signoutRedirect(); await (await getUserManagers())[activeRole].signoutRedirect();
authStorage.deleteActiveRole(); authStorage.deleteActiveRole();
} }
} }