@riocrypto/common-server 1.0.1484 → 1.0.1485
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.
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import { AuthRole } from "@riocrypto/common";
|
|
2
2
|
import { NextFunction, Request, Response } from "express";
|
|
3
|
-
export declare const
|
|
3
|
+
export declare const requireMinRole: (req: Request, res: Response, next: NextFunction, minRole: AuthRole) => Promise<void>;
|
|
@@ -9,15 +9,20 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
9
9
|
});
|
|
10
10
|
};
|
|
11
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
-
exports.
|
|
12
|
+
exports.requireMinRole = void 0;
|
|
13
13
|
const common_1 = require("@riocrypto/common");
|
|
14
|
-
const
|
|
14
|
+
const authRoleOrder = [
|
|
15
|
+
common_1.AuthRole.Read,
|
|
16
|
+
common_1.AuthRole.Write,
|
|
17
|
+
common_1.AuthRole.Owner,
|
|
18
|
+
];
|
|
19
|
+
const requireMinRole = (req, res, next, minRole) => __awaiter(void 0, void 0, void 0, function* () {
|
|
20
|
+
var _a;
|
|
15
21
|
if (!req.admin) {
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
throw new common_1.GenericInputError(`Insufficient permissions. This endpoint requires the ${role} role. Contact your account owner to change your access role.`);
|
|
22
|
+
if (authRoleOrder.indexOf((_a = req.auth) === null || _a === void 0 ? void 0 : _a.role) >= authRoleOrder.indexOf(minRole)) {
|
|
23
|
+
throw new common_1.GenericInputError(`Insufficient permissions. This endpoint requires at least the ${minRole} role. Contact your account owner to change your access role.`);
|
|
19
24
|
}
|
|
20
25
|
}
|
|
21
26
|
next();
|
|
22
27
|
});
|
|
23
|
-
exports.
|
|
28
|
+
exports.requireMinRole = requireMinRole;
|