@munlib/common 1.0.110 → 1.0.112

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.
@@ -26,7 +26,7 @@ var NotAuthorizedError = /** @class */ (function (_super) {
26
26
  return _this;
27
27
  }
28
28
  NotAuthorizedError.prototype.serializeErrors = function () {
29
- return [{ message: 'Not authorized' }];
29
+ return [{ message: 'Token Not authorized' }];
30
30
  };
31
31
  return NotAuthorizedError;
32
32
  }(custom_error_1.CustomError));
@@ -27,5 +27,6 @@ export declare enum QueueNames {
27
27
  }
28
28
  export declare enum Instituciones {
29
29
  ETAPA = "ETAPA",
30
- MUNICIPIO = "MUNICIPIO"
30
+ MUNICIPIO = "MUNICIPIO",
31
+ EMOV = "EMOV"
31
32
  }
@@ -36,4 +36,5 @@ var Instituciones;
36
36
  (function (Instituciones) {
37
37
  Instituciones["ETAPA"] = "ETAPA";
38
38
  Instituciones["MUNICIPIO"] = "MUNICIPIO";
39
+ Instituciones["EMOV"] = "EMOV";
39
40
  })(Instituciones || (exports.Instituciones = Instituciones = {}));
@@ -17,4 +17,5 @@ declare global {
17
17
  }
18
18
  }
19
19
  export declare const requireAuth: (req: Request, res: Response, next: NextFunction) => void;
20
+ export declare const requireAuthAdmin: (req: Request, res: Response, next: NextFunction) => void;
20
21
  export {};
@@ -3,7 +3,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.requireAuth = void 0;
6
+ exports.requireAuthAdmin = exports.requireAuth = void 0;
7
7
  var not_authorized_error_1 = require("../errors/not-authorized-error");
8
8
  var jsonwebtoken_1 = __importDefault(require("jsonwebtoken"));
9
9
  var requireAuth = function (req, res, next) {
@@ -25,3 +25,25 @@ var requireAuth = function (req, res, next) {
25
25
  next();
26
26
  };
27
27
  exports.requireAuth = requireAuth;
28
+ var requireAuthAdmin = function (req, res, next) {
29
+ // Extraer el JWT del encabezado de autorización
30
+ var authorizationHeader = req.headers["authorization"];
31
+ if (!authorizationHeader || !authorizationHeader.startsWith("Bearer ")) {
32
+ throw new not_authorized_error_1.NotAuthorizedError();
33
+ }
34
+ var token = authorizationHeader.split(" ")[1];
35
+ try {
36
+ // Verificar y decodificar el JWT
37
+ var payload = jsonwebtoken_1.default.verify(token, process.env.JWT_KEY);
38
+ req.currentUser = payload;
39
+ if (!payload.isAdmin) {
40
+ throw new not_authorized_error_1.NotAuthorizedError();
41
+ }
42
+ }
43
+ catch (err) {
44
+ console.log("Error al verificar el token:", err);
45
+ throw new not_authorized_error_1.NotAuthorizedError();
46
+ }
47
+ next();
48
+ };
49
+ exports.requireAuthAdmin = requireAuthAdmin;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@munlib/common",
3
- "version": "1.0.110",
3
+ "version": "1.0.112",
4
4
  "description": "",
5
5
  "main": "./build/index.js",
6
6
  "types": "./build/index.d.ts",