mirror of
https://github.com/awatertrevi/infisical.git
synced 2026-10-14 07:30:20 +00:00
27 lines
707 B
TypeScript
27 lines
707 B
TypeScript
import { NextFunction, Request, Response } from "express";
|
|
import { Types } from "mongoose";
|
|
import { validateClientForBot } from "../validation";
|
|
|
|
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; |