@riocrypto/common 1.0.394 → 1.0.395
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.
|
@@ -23,7 +23,7 @@ const kyc_status_1 = require("../types/kyc-status");
|
|
|
23
23
|
const missing_kyc_approval_error_1 = require("../errors/missing-kyc-approval-error");
|
|
24
24
|
const missing_user_error_1 = require("../errors/missing-user-error");
|
|
25
25
|
const authorize = (req, res, next, mongoose, authorizationTypes) => __awaiter(void 0, void 0, void 0, function* () {
|
|
26
|
-
var _a, _b;
|
|
26
|
+
var _a, _b, _c;
|
|
27
27
|
let missingKYC = false;
|
|
28
28
|
if (authorizationTypes.includes(authorization_type_1.AuthorizationType.Auth)) {
|
|
29
29
|
if ((_a = req.cookies) === null || _a === void 0 ? void 0 : _a.jwt) {
|
|
@@ -107,13 +107,19 @@ const authorize = (req, res, next, mongoose, authorizationTypes) => __awaiter(vo
|
|
|
107
107
|
req.user = user;
|
|
108
108
|
}
|
|
109
109
|
}
|
|
110
|
+
if ((_c = req.cookies) === null || _c === void 0 ? void 0 : _c.jwt) {
|
|
111
|
+
try {
|
|
112
|
+
const payload = jsonwebtoken_1.default.verify(req.cookies.jwt, process.env.JWT_KEY);
|
|
113
|
+
if (authorizationTypes.includes(authorization_type_1.AuthorizationType.User) && !req.user) {
|
|
114
|
+
throw new missing_user_error_1.MissingUserError();
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
catch (err) { }
|
|
118
|
+
}
|
|
110
119
|
if (!req.currentAdminAuth && !req.currentAuth && !req.user) {
|
|
111
120
|
if (missingKYC) {
|
|
112
121
|
throw new missing_kyc_approval_error_1.MissingKYCApprovalError();
|
|
113
122
|
}
|
|
114
|
-
if (authorizationTypes.includes(authorization_type_1.AuthorizationType.User) && !req.user) {
|
|
115
|
-
throw new missing_user_error_1.MissingUserError();
|
|
116
|
-
}
|
|
117
123
|
throw new not_authorized_error_1.NotAuthorizedError();
|
|
118
124
|
}
|
|
119
125
|
next();
|