1 | "use strict";
|
2 | Object.defineProperty(exports, "__esModule", { value: true });
|
3 | const tslib_1 = require("tslib");
|
4 | const errors_1 = require("../errors");
|
5 | function AuthMiddleware(authChecker, authMode, roles) {
|
6 | return (action, next) => tslib_1.__awaiter(this, void 0, void 0, function* () {
|
7 | const accessGranted = yield authChecker(action, roles);
|
8 | if (!accessGranted) {
|
9 | if (authMode === "null") {
|
10 | return null;
|
11 | }
|
12 | else if (authMode === "error") {
|
13 | throw roles.length === 0 ? new errors_1.UnauthorizedError() : new errors_1.ForbiddenError();
|
14 | }
|
15 | }
|
16 | return next();
|
17 | });
|
18 | }
|
19 | exports.AuthMiddleware = AuthMiddleware;
|