mirror of
https://github.com/awatertrevi/infisical.git
synced 2026-10-12 03:29:18 +00:00
30 lines
855 B
TypeScript
30 lines
855 B
TypeScript
import { Request, Response, NextFunction } from 'express';
|
|
import { Types } from 'mongoose';
|
|
import { Bot } from '../models';
|
|
import { validateMembership } from '../helpers/membership';
|
|
import { validateClientForBot } from '../helpers/bot';
|
|
import { AccountNotFoundError } from '../utils/errors';
|
|
|
|
type req = 'params' | 'body' | 'query';
|
|
|
|
const requireBotAuth = ({
|
|
acceptedRoles,
|
|
locationBotId = 'params'
|
|
}: {
|
|
acceptedRoles: Array<'admin' | 'member'>;
|
|
locationBotId?: req;
|
|
}) => {
|
|
return async (req: Request, res: Response, next: NextFunction) => {
|
|
const { botId } = req[locationBotId];
|
|
|
|
req.bot = await validateClientForBot({
|
|
authData: req.authData,
|
|
botId: new Types.ObjectId(botId),
|
|
acceptedRoles
|
|
});
|
|
|
|
next();
|
|
}
|
|
}
|
|
|
|
export default requireBotAuth; |