@riocrypto/common 1.0.391 → 1.0.394

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