Add various participant and role controllers

+ Fix issues
This commit is contained in:
Stephan
2022-06-09 16:23:54 +02:00
committed by La_Felx
parent 7136c91e72
commit 87f5fa2e91
2 changed files with 114 additions and 11 deletions
+10 -1
View File
@@ -10,6 +10,10 @@ export interface TeamleaderJWTPayload {
team: string;
}
export function isTeamleaderJWTPayload(payload: any): payload is TeamleaderJWTPayload {
return typeof payload.team === "string";
}
const JWT_SECRET = process.env.JWT_SECRET;
export function generateTeamleaderJWT(teamleader: Team) {
@@ -86,8 +90,13 @@ export const _requireTeamleaderAuthentication =
export const requireTeamleaderAuthentication = _requireTeamleaderAuthentication({ optional: false, controlled: false });
export async function requireLeaderOfTeam(auth: TeamleaderJWTPayload | undefined, teamPid: string) {
export async function requireLeaderOfTeam(auth: TeamleaderJWTPayload | undefined, teamPid?: string) {
if (!teamPid) {
throw new AuthError("Could not match IDs");
}
await checkTeamExistence(teamPid);
if (auth?.team !== teamPid) {
throw new AuthError("The provided authorization is not valid for the requested team");
}