feat: Mechanisme voor automatische aanmaak en update van accounts aangemaakt.

This commit is contained in:
Gerald Schmittinger 2025-04-08 14:24:57 +02:00
parent 6cb8a1b98f
commit 9339eca9cf
9 changed files with 84 additions and 23 deletions

View file

@ -1,4 +1,9 @@
import { envVars, getEnvVar } from '../util/envVars.js';
import {AuthenticatedRequest} from "../middleware/auth/authenticated-request";
import {createStudent} from "../services/students";
import {AuthenticationInfo} from "../middleware/auth/authentication-info";
import {Request, Response} from "express";
import {createTeacher} from "../services/teachers";
interface FrontendIdpConfig {
authority: string;
@ -15,7 +20,7 @@ interface FrontendAuthConfig {
const SCOPE = 'openid profile email';
const RESPONSE_TYPE = 'code';
export function getFrontendAuthConfig(): FrontendAuthConfig {
function getFrontendAuthConfig(): FrontendAuthConfig {
return {
student: {
authority: getEnvVar(envVars.IdpStudentUrl),
@ -31,3 +36,26 @@ export function getFrontendAuthConfig(): FrontendAuthConfig {
},
};
}
export function handleGetFrontendAuthConfig(_req: Request, res: Response): void {
res.json(getFrontendAuthConfig());
}
export async function handleHello(req: AuthenticatedRequest) {
const auth: AuthenticationInfo = req.auth!;
if (auth.accountType === "teacher") {
await createTeacher({
id: auth.username,
username: auth.username,
firstName: auth.firstName ?? "",
lastName: auth.lastName ?? "",
}, true);
} else {
await createStudent({
id: auth.username,
username: auth.username,
firstName: auth.firstName ?? "",
lastName: auth.lastName ?? "",
}, true);
}
}