@otters.ai/common-backend 1.0.190 → 1.0.191
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @param {*} req Express req Object
|
|
3
|
+
* @param {*} res Express res Object
|
|
4
|
+
* @param {*} next Express next Function
|
|
5
|
+
*/
|
|
6
|
+
type RolePermissions = Record<string, string[]>;
|
|
7
|
+
export declare const checkRole: (rolesPermissions: RolePermissions, requiredPermission: string, role: string, req: any, res: any, next: any) => any;
|
|
8
|
+
export {};
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* @param {*} req Express req Object
|
|
4
|
+
* @param {*} res Express res Object
|
|
5
|
+
* @param {*} next Express next Function
|
|
6
|
+
*/
|
|
7
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
8
|
+
exports.checkRole = void 0;
|
|
9
|
+
const checkRole = (rolesPermissions, requiredPermission, role, req, res, next) => {
|
|
10
|
+
try {
|
|
11
|
+
const permissions = rolesPermissions[role] || [];
|
|
12
|
+
if (!permissions.includes(requiredPermission)) {
|
|
13
|
+
return res.status(200).json({
|
|
14
|
+
success: false,
|
|
15
|
+
message: 'Access denied',
|
|
16
|
+
});
|
|
17
|
+
}
|
|
18
|
+
next();
|
|
19
|
+
}
|
|
20
|
+
catch (error) {
|
|
21
|
+
return next(error);
|
|
22
|
+
}
|
|
23
|
+
};
|
|
24
|
+
exports.checkRole = checkRole;
|