@riocrypto/common 1.0.388 → 1.0.390

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.
@@ -33,6 +33,7 @@ const authorize = (req, res, next, mongoose, authorizationTypes) => __awaiter(vo
33
33
  }
34
34
  if (authorizationTypes.includes(authorization_type_1.AuthorizationType.Admin)) {
35
35
  if ((_b = req.cookies) === null || _b === void 0 ? void 0 : _b.adminJwt) {
36
+ console.log("got admin");
36
37
  try {
37
38
  const payload = jsonwebtoken_1.default.verify(req.cookies.adminJwt, process.env.JWT_KEY_ADMIN);
38
39
  req.currentAdminAuth = payload;
@@ -99,10 +100,15 @@ const authorize = (req, res, next, mongoose, authorizationTypes) => __awaiter(vo
99
100
  }
100
101
  const user = individualUser || businessUser;
101
102
  if (user) {
103
+ console.log("got user");
102
104
  req.user = user;
103
105
  }
104
106
  }
107
+ console.log("currentAdminAuth", req.currentAdminAuth);
108
+ console.log("currentAuth", req.currentAuth);
109
+ console.log("user", req.user);
105
110
  if (!req.currentAdminAuth && !req.currentAuth && !req.user) {
111
+ console.log("throwing error");
106
112
  throw new not_authorized_error_1.NotAuthorizedError();
107
113
  }
108
114
  next();
@@ -10,9 +10,11 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
10
10
  };
11
11
  Object.defineProperty(exports, "__esModule", { value: true });
12
12
  exports.getOrder = void 0;
13
+ const not_authorized_error_1 = require("../errors/not-authorized-error");
13
14
  const not_found_error_1 = require("../errors/not-found-error");
14
15
  const order_1 = require("../models/order");
15
16
  const getOrder = (req, res, next, mongoose) => __awaiter(void 0, void 0, void 0, function* () {
17
+ var _a;
16
18
  let orderId = "";
17
19
  if (req.body.orderId) {
18
20
  orderId = req.body.orderId;
@@ -37,6 +39,9 @@ const getOrder = (req, res, next, mongoose) => __awaiter(void 0, void 0, void 0,
37
39
  catch (error) {
38
40
  throw new not_found_error_1.NotFoundError();
39
41
  }
42
+ if (req.order.userId !== ((_a = req.user) === null || _a === void 0 ? void 0 : _a.id) && !req.currentAdminAuth) {
43
+ throw new not_authorized_error_1.NotAuthorizedError();
44
+ }
40
45
  next();
41
46
  });
42
47
  exports.getOrder = getOrder;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@riocrypto/common",
3
- "version": "1.0.388",
3
+ "version": "1.0.390",
4
4
  "description": "",
5
5
  "main": "./build/index.js",
6
6
  "types": "./build/index.d.ts",