From d10e6ea5191bc271f09981aed2fc179e9caebd29 Mon Sep 17 00:00:00 2001 From: juancarmore Date: Wed, 26 Mar 2025 12:39:10 +0100 Subject: [PATCH] backend: Add comments in middlewares for clarity --- backend/src/middlewares/participant.middleware.ts | 7 +++++++ backend/src/middlewares/room.middleware.ts | 7 +++++++ 2 files changed, 14 insertions(+) diff --git a/backend/src/middlewares/participant.middleware.ts b/backend/src/middlewares/participant.middleware.ts index ab326af..96f0e43 100644 --- a/backend/src/middlewares/participant.middleware.ts +++ b/backend/src/middlewares/participant.middleware.ts @@ -4,6 +4,13 @@ import { container } from '../config/dependency-injector.config.js'; import { GlobalPreferencesService, LoggerService, RoomService } from '../services/index.js'; import { allowAnonymous, tokenAndRoleValidator, withAuth } from './auth.middleware.js'; +/** + * Middleware to configure authentication based on participant role and authentication mode for entering a room. + * + * - If the authentication mode is MODERATORS_ONLY and the participant role is MODERATOR, configure user authentication. + * - If the authentication mode is ALL_USERS, configure user authentication. + * - Otherwise, allow anonymous access. + */ export const configureTokenAuth = async (req: Request, res: Response, next: NextFunction) => { const logger = container.get(LoggerService); const globalPrefService = container.get(GlobalPreferencesService); diff --git a/backend/src/middlewares/room.middleware.ts b/backend/src/middlewares/room.middleware.ts index ed97a66..47253b2 100644 --- a/backend/src/middlewares/room.middleware.ts +++ b/backend/src/middlewares/room.middleware.ts @@ -5,6 +5,13 @@ import { GlobalPreferencesService } from '../services/index.js'; import { allowAnonymous, apiKeyValidator, tokenAndRoleValidator, withAuth } from './auth.middleware.js'; import { AuthMode, ParticipantRole, UserRole } from '@typings-ce'; +/** + * Middleware that configures authentication for creating a room based on global settings. + * + * - Admin role and API key authentication methods are always allowed. + * - If room creation is allowed and requires authentication, the user must have a valid token. + * - If room creation is allowed and does not require authentication, anonymous users are allowed. + */ export const configureCreateRoomAuth = async (req: Request, res: Response, next: NextFunction) => { const logger = container.get(LoggerService); const globalPrefService = container.get(GlobalPreferencesService);