fix: Fouten in implementatie van hello-mechanisme opgelost.

This commit is contained in:
Gerald Schmittinger 2025-04-19 16:47:47 +02:00
parent 59569445c3
commit 57ff2daf6c
5 changed files with 31 additions and 12 deletions

View file

@ -1,4 +1,5 @@
import { UnauthorizedException } from '../exceptions/unauthorized-exception.js';
import { getLogger } from '../logging/initalize.js';
import { AuthenticatedRequest } from '../middleware/auth/authenticated-request.js';
import { createOrUpdateStudent } from '../services/students.js';
import { createOrUpdateTeacher } from '../services/teachers.js';
@ -20,6 +21,8 @@ interface FrontendAuthConfig {
const SCOPE = 'openid profile email';
const RESPONSE_TYPE = 'code';
const logger = getLogger();
export function getFrontendAuthConfig(): FrontendAuthConfig {
return {
student: {
@ -37,7 +40,7 @@ export function getFrontendAuthConfig(): FrontendAuthConfig {
};
}
export async function postHelloHandler(req: AuthenticatedRequest, _res: Response): Promise<void> {
export async function postHelloHandler(req: AuthenticatedRequest, res: Response): Promise<void> {
const auth = req.auth;
if (!auth) {
throw new UnauthorizedException("Cannot say hello when not authenticated.");
@ -49,8 +52,11 @@ export async function postHelloHandler(req: AuthenticatedRequest, _res: Response
lastName: auth.lastName ?? ''
};
if (auth.accountType === "student") {
await createOrUpdateStudent({ ...userData }, { preventOverwrite: false });
await createOrUpdateStudent(userData);
logger.debug(`Synchronized student ${userData.username} with IDP`);
} else {
await createOrUpdateTeacher({ ...userData }, { preventOverwrite: false });
await createOrUpdateTeacher(userData);
logger.debug(`Synchronized teacher ${userData.username} with IDP`);
}
res.status(200).send({ message: "Welcome!" });
}