backend: Rename configureTokenAuth middleware to configureParticipantTokenAuth and improve error handling
This commit is contained in:
parent
4271d6abc5
commit
8bbbee731b
@ -1,6 +1,7 @@
|
|||||||
import { AuthMode, ParticipantOptions, ParticipantRole, UserRole } from '@typings-ce';
|
import { AuthMode, ParticipantOptions, ParticipantRole, UserRole } from '@typings-ce';
|
||||||
import { NextFunction, Request, Response } from 'express';
|
import { NextFunction, Request, Response } from 'express';
|
||||||
import { container } from '../config/index.js';
|
import { container } from '../config/index.js';
|
||||||
|
import { OpenViduMeetError } from '../models/error.model.js';
|
||||||
import { LoggerService, MeetStorageService, RoomService } from '../services/index.js';
|
import { LoggerService, MeetStorageService, RoomService } from '../services/index.js';
|
||||||
import { allowAnonymous, tokenAndRoleValidator, withAuth } from './auth.middleware.js';
|
import { allowAnonymous, tokenAndRoleValidator, withAuth } from './auth.middleware.js';
|
||||||
|
|
||||||
@ -11,7 +12,7 @@ import { allowAnonymous, tokenAndRoleValidator, withAuth } from './auth.middlewa
|
|||||||
* - If the authentication mode is ALL_USERS, configure user authentication.
|
* - If the authentication mode is ALL_USERS, configure user authentication.
|
||||||
* - Otherwise, allow anonymous access.
|
* - Otherwise, allow anonymous access.
|
||||||
*/
|
*/
|
||||||
export const configureTokenAuth = async (req: Request, res: Response, next: NextFunction) => {
|
export const configureParticipantTokenAuth = async (req: Request, res: Response, next: NextFunction) => {
|
||||||
const logger = container.get(LoggerService);
|
const logger = container.get(LoggerService);
|
||||||
const globalPrefService = container.get(MeetStorageService);
|
const globalPrefService = container.get(MeetStorageService);
|
||||||
const roomService = container.get(RoomService);
|
const roomService = container.get(RoomService);
|
||||||
@ -22,8 +23,16 @@ export const configureTokenAuth = async (req: Request, res: Response, next: Next
|
|||||||
const { roomId, secret } = req.body as ParticipantOptions;
|
const { roomId, secret } = req.body as ParticipantOptions;
|
||||||
role = await roomService.getRoomRoleBySecret(roomId, secret);
|
role = await roomService.getRoomRoleBySecret(roomId, secret);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
logger.error('Error getting room secret role', error);
|
logger.error('Error getting room role by secret', error);
|
||||||
return res.status(500).json({ message: 'Internal server error' });
|
|
||||||
|
if (error instanceof OpenViduMeetError) {
|
||||||
|
return res.status(error.statusCode).json({ name: error.name, message: error.message });
|
||||||
|
} else {
|
||||||
|
return res.status(500).json({
|
||||||
|
name: 'Participant Error',
|
||||||
|
message: 'Internal server error. Participant operation failed'
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
let authMode: AuthMode;
|
let authMode: AuthMode;
|
||||||
|
|||||||
@ -1,7 +1,7 @@
|
|||||||
import bodyParser from 'body-parser';
|
import bodyParser from 'body-parser';
|
||||||
import { Router } from 'express';
|
import { Router } from 'express';
|
||||||
import * as participantCtrl from '../controllers/participant.controller.js';
|
import * as participantCtrl from '../controllers/participant.controller.js';
|
||||||
import { configureTokenAuth, validateParticipantTokenRequest } from '../middlewares/index.js';
|
import { configureParticipantTokenAuth, validateParticipantTokenRequest } from '../middlewares/index.js';
|
||||||
|
|
||||||
export const internalParticipantRouter = Router();
|
export const internalParticipantRouter = Router();
|
||||||
internalParticipantRouter.use(bodyParser.urlencoded({ extended: true }));
|
internalParticipantRouter.use(bodyParser.urlencoded({ extended: true }));
|
||||||
@ -11,12 +11,12 @@ internalParticipantRouter.use(bodyParser.json());
|
|||||||
internalParticipantRouter.post(
|
internalParticipantRouter.post(
|
||||||
'/token',
|
'/token',
|
||||||
validateParticipantTokenRequest,
|
validateParticipantTokenRequest,
|
||||||
configureTokenAuth,
|
configureParticipantTokenAuth,
|
||||||
participantCtrl.generateParticipantToken
|
participantCtrl.generateParticipantToken
|
||||||
);
|
);
|
||||||
internalParticipantRouter.post(
|
internalParticipantRouter.post(
|
||||||
'/token/refresh',
|
'/token/refresh',
|
||||||
validateParticipantTokenRequest,
|
validateParticipantTokenRequest,
|
||||||
configureTokenAuth,
|
configureParticipantTokenAuth,
|
||||||
participantCtrl.refreshParticipantToken
|
participantCtrl.refreshParticipantToken
|
||||||
);
|
);
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user