Merge branch 'fix/verschillende-authenticatieproblemen' of https://github.com/SELab-2/Dwengo-1 into fix/verschillende-authenticatieproblemen
This commit is contained in:
		
						commit
						58884ade3d
					
				
					 9 changed files with 23 additions and 15 deletions
				
			
		|  | @ -4,7 +4,7 @@ import { AuthenticatedRequest } from '../middleware/auth/authenticated-request.j | |||
| import { createOrUpdateStudent } from '../services/students.js'; | ||||
| import { createOrUpdateTeacher } from '../services/teachers.js'; | ||||
| import { envVars, getEnvVar } from '../util/envVars.js'; | ||||
| import { Response } from "express"; | ||||
| import { Response } from 'express'; | ||||
| 
 | ||||
| interface FrontendIdpConfig { | ||||
|     authority: string; | ||||
|  | @ -43,20 +43,20 @@ export function getFrontendAuthConfig(): FrontendAuthConfig { | |||
| 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."); | ||||
|         throw new UnauthorizedException('Cannot say hello when not authenticated.'); | ||||
|     } | ||||
|     const userData = { | ||||
|         id: auth.username, | ||||
|         username: auth.username, | ||||
|         firstName: auth.firstName ?? '', | ||||
|         lastName: auth.lastName ?? '' | ||||
|         lastName: auth.lastName ?? '', | ||||
|     }; | ||||
|     if (auth.accountType === "student") { | ||||
|     if (auth.accountType === 'student') { | ||||
|         await createOrUpdateStudent(userData); | ||||
|         logger.debug(`Synchronized student ${userData.username} with IDP`); | ||||
|     } else { | ||||
|         await createOrUpdateTeacher(userData); | ||||
|         logger.debug(`Synchronized teacher ${userData.username} with IDP`); | ||||
|     } | ||||
|     res.status(200).send({ message: "Welcome!" }); | ||||
|     res.status(200).send({ message: 'Welcome!' }); | ||||
| } | ||||
|  |  | |||
|  | @ -1,4 +1,4 @@ | |||
| import { HasStatusCode } from "./has-status-code"; | ||||
| import { HasStatusCode } from './has-status-code'; | ||||
| 
 | ||||
| /** | ||||
|  * Exceptions which are associated with a HTTP error code. | ||||
|  |  | |||
|  | @ -1,5 +1,5 @@ | |||
| export interface HasStatusCode { | ||||
|     status: number | ||||
|     status: number; | ||||
| } | ||||
| export function hasStatusCode(err: unknown): err is HasStatusCode { | ||||
|     return typeof err === 'object' && err !== null && 'status' in err && typeof (err as HasStatusCode)?.status === 'number'; | ||||
|  |  | |||
|  | @ -48,7 +48,7 @@ const idpConfigs = { | |||
| const verifyJwtToken = expressjwt({ | ||||
|     secret: async (_: express.Request, token: jwt.Jwt | undefined) => { | ||||
|         if (!token?.payload || !(token.payload as JwtPayload).iss) { | ||||
|             throw new UnauthorizedException("Invalid token.") | ||||
|             throw new UnauthorizedException('Invalid token.'); | ||||
|         } | ||||
| 
 | ||||
|         const issuer = (token.payload as JwtPayload).iss; | ||||
|  |  | |||
|  | @ -71,7 +71,7 @@ export async function createOrUpdateStudent(userData: StudentDTO): Promise<Stude | |||
|     await getStudentRepository().upsert({ | ||||
|         username: userData.username, | ||||
|         firstName: userData.firstName, | ||||
|         lastName: userData.lastName | ||||
|         lastName: userData.lastName, | ||||
|     }); | ||||
|     return userData; | ||||
| } | ||||
|  |  | |||
|  | @ -70,7 +70,7 @@ export async function createOrUpdateTeacher(userData: TeacherDTO): Promise<Teach | |||
|     await getTeacherRepository().upsert({ | ||||
|         username: userData.username, | ||||
|         firstName: userData.firstName, | ||||
|         lastName: userData.lastName | ||||
|         lastName: userData.lastName, | ||||
|     }); | ||||
|     return userData; | ||||
| } | ||||
|  |  | |||
		Reference in a new issue
	
	 Gerald Schmittinger
						Gerald Schmittinger