@riocrypto/common 1.0.391 → 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,10 +20,11 @@ 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
|
-
console.log("got auth");
|
|
27
28
|
if ((_a = req.cookies) === null || _a === void 0 ? void 0 : _a.jwt) {
|
|
28
29
|
try {
|
|
29
30
|
const payload = jsonwebtoken_1.default.verify(req.cookies.jwt, process.env.JWT_KEY);
|
|
@@ -34,7 +35,6 @@ const authorize = (req, res, next, mongoose, authorizationTypes) => __awaiter(vo
|
|
|
34
35
|
}
|
|
35
36
|
if (authorizationTypes.includes(authorization_type_1.AuthorizationType.Admin)) {
|
|
36
37
|
if ((_b = req.cookies) === null || _b === void 0 ? void 0 : _b.adminJwt) {
|
|
37
|
-
console.log("got admin");
|
|
38
38
|
try {
|
|
39
39
|
const payload = jsonwebtoken_1.default.verify(req.cookies.adminJwt, process.env.JWT_KEY_ADMIN);
|
|
40
40
|
req.currentAdminAuth = payload;
|
|
@@ -80,6 +80,7 @@ const authorize = (req, res, next, mongoose, authorizationTypes) => __awaiter(vo
|
|
|
80
80
|
attributes: { $ne: user_attribute_1.UserAttribute.deleted },
|
|
81
81
|
});
|
|
82
82
|
if ((individualUser === null || individualUser === void 0 ? void 0 : individualUser.kycStatus) !== kyc_status_1.KYCStatus.Passed) {
|
|
83
|
+
missingKYC = true;
|
|
83
84
|
throw new Error();
|
|
84
85
|
}
|
|
85
86
|
}
|
|
@@ -93,6 +94,7 @@ const authorize = (req, res, next, mongoose, authorizationTypes) => __awaiter(vo
|
|
|
93
94
|
attributes: { $ne: user_attribute_1.UserAttribute.deleted },
|
|
94
95
|
});
|
|
95
96
|
if ((businessUser === null || businessUser === void 0 ? void 0 : businessUser.kycStatus) !== kyc_status_1.KYCStatus.businessApproved) {
|
|
97
|
+
missingKYC = true;
|
|
96
98
|
throw new Error();
|
|
97
99
|
}
|
|
98
100
|
}
|
|
@@ -101,15 +103,13 @@ const authorize = (req, res, next, mongoose, authorizationTypes) => __awaiter(vo
|
|
|
101
103
|
}
|
|
102
104
|
const user = individualUser || businessUser;
|
|
103
105
|
if (user) {
|
|
104
|
-
console.log("got user");
|
|
105
106
|
req.user = user;
|
|
106
107
|
}
|
|
107
108
|
}
|
|
108
|
-
console.log("currentAdminAuth", req.currentAdminAuth);
|
|
109
|
-
console.log("currentAuth", req.currentAuth);
|
|
110
|
-
console.log("user", req.user);
|
|
111
109
|
if (!req.currentAdminAuth && !req.currentAuth && !req.user) {
|
|
112
|
-
|
|
110
|
+
if (missingKYC) {
|
|
111
|
+
throw new missing_kyc_approval_error_1.MissingKYCApprovalError();
|
|
112
|
+
}
|
|
113
113
|
throw new not_authorized_error_1.NotAuthorizedError();
|
|
114
114
|
}
|
|
115
115
|
next();
|