@riocrypto/common 1.0.390 → 1.0.392

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.
@@ -20,8 +20,10 @@ const authorization_type_1 = require("../types/authorization-type");
20
20
  const jsonwebtoken_1 = __importDefault(require("jsonwebtoken"));
21
21
  const not_authorized_error_1 = require("../errors/not-authorized-error");
22
22
  const kyc_status_1 = require("../types/kyc-status");
23
+ const missing_kyc_approval_error_1 = require("../errors/missing-kyc-approval-error");
23
24
  const authorize = (req, res, next, mongoose, authorizationTypes) => __awaiter(void 0, void 0, void 0, function* () {
24
25
  var _a, _b;
26
+ let missingKYC = false;
25
27
  if (authorizationTypes.includes(authorization_type_1.AuthorizationType.Auth)) {
26
28
  if ((_a = req.cookies) === null || _a === void 0 ? void 0 : _a.jwt) {
27
29
  try {
@@ -33,7 +35,6 @@ const authorize = (req, res, next, mongoose, authorizationTypes) => __awaiter(vo
33
35
  }
34
36
  if (authorizationTypes.includes(authorization_type_1.AuthorizationType.Admin)) {
35
37
  if ((_b = req.cookies) === null || _b === void 0 ? void 0 : _b.adminJwt) {
36
- console.log("got admin");
37
38
  try {
38
39
  const payload = jsonwebtoken_1.default.verify(req.cookies.adminJwt, process.env.JWT_KEY_ADMIN);
39
40
  req.currentAdminAuth = payload;
@@ -79,6 +80,7 @@ const authorize = (req, res, next, mongoose, authorizationTypes) => __awaiter(vo
79
80
  attributes: { $ne: user_attribute_1.UserAttribute.deleted },
80
81
  });
81
82
  if ((individualUser === null || individualUser === void 0 ? void 0 : individualUser.kycStatus) !== kyc_status_1.KYCStatus.Passed) {
83
+ missingKYC = true;
82
84
  throw new Error();
83
85
  }
84
86
  }
@@ -92,6 +94,7 @@ const authorize = (req, res, next, mongoose, authorizationTypes) => __awaiter(vo
92
94
  attributes: { $ne: user_attribute_1.UserAttribute.deleted },
93
95
  });
94
96
  if ((businessUser === null || businessUser === void 0 ? void 0 : businessUser.kycStatus) !== kyc_status_1.KYCStatus.businessApproved) {
97
+ missingKYC = true;
95
98
  throw new Error();
96
99
  }
97
100
  }
@@ -100,15 +103,13 @@ const authorize = (req, res, next, mongoose, authorizationTypes) => __awaiter(vo
100
103
  }
101
104
  const user = individualUser || businessUser;
102
105
  if (user) {
103
- console.log("got user");
104
106
  req.user = user;
105
107
  }
106
108
  }
107
- console.log("currentAdminAuth", req.currentAdminAuth);
108
- console.log("currentAuth", req.currentAuth);
109
- console.log("user", req.user);
110
109
  if (!req.currentAdminAuth && !req.currentAuth && !req.user) {
111
- console.log("throwing error");
110
+ if (missingKYC) {
111
+ throw new missing_kyc_approval_error_1.MissingKYCApprovalError();
112
+ }
112
113
  throw new not_authorized_error_1.NotAuthorizedError();
113
114
  }
114
115
  next();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@riocrypto/common",
3
- "version": "1.0.390",
3
+ "version": "1.0.392",
4
4
  "description": "",
5
5
  "main": "./build/index.js",
6
6
  "types": "./build/index.d.ts",