@riocrypto/common 1.0.430 → 1.0.432
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.
|
@@ -25,12 +25,14 @@ const missing_user_error_1 = require("../errors/missing-user-error");
|
|
|
25
25
|
const missing_password_error_1 = require("../errors/missing-password-error");
|
|
26
26
|
const missing_security_question_error_1 = require("../errors/missing-security-question-error");
|
|
27
27
|
const admin_only_error_1 = require("../errors/admin-only-error");
|
|
28
|
+
const not_broker_error_1 = require("../errors/not-broker-error");
|
|
28
29
|
const authorize = (req, res, next, mongoose, authorizationTypes) => __awaiter(void 0, void 0, void 0, function* () {
|
|
29
|
-
var _a, _b, _c, _d, _e, _f, _g, _h;
|
|
30
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j;
|
|
30
31
|
let missingKYC = false;
|
|
31
32
|
if (authorizationTypes.includes(authorization_type_1.AuthorizationType.Auth) ||
|
|
32
33
|
authorizationTypes.includes(authorization_type_1.AuthorizationType.UserNoKYC) ||
|
|
33
|
-
authorizationTypes.includes(authorization_type_1.AuthorizationType.User)
|
|
34
|
+
authorizationTypes.includes(authorization_type_1.AuthorizationType.User) ||
|
|
35
|
+
authorizationTypes.includes(authorization_type_1.AuthorizationType.Broker)) {
|
|
34
36
|
if ((_a = req.cookies) === null || _a === void 0 ? void 0 : _a.jwt) {
|
|
35
37
|
try {
|
|
36
38
|
const payload = jsonwebtoken_1.default.verify(req.cookies.jwt, process.env.JWT_KEY);
|
|
@@ -106,7 +108,6 @@ const authorize = (req, res, next, mongoose, authorizationTypes) => __awaiter(vo
|
|
|
106
108
|
const BusinessUser = yield (0, business_user_1.buildBusinessUser)(mongoose);
|
|
107
109
|
businessUser = yield BusinessUser.findOne({
|
|
108
110
|
authId: req.currentAuth.id,
|
|
109
|
-
attributes: { $ne: user_attribute_1.UserAttribute.deleted },
|
|
110
111
|
});
|
|
111
112
|
if (!businessUser) {
|
|
112
113
|
throw new Error();
|
|
@@ -124,6 +125,27 @@ const authorize = (req, res, next, mongoose, authorizationTypes) => __awaiter(vo
|
|
|
124
125
|
req.user = user;
|
|
125
126
|
}
|
|
126
127
|
}
|
|
128
|
+
if (authorizationTypes.includes(authorization_type_1.AuthorizationType.Broker)) {
|
|
129
|
+
let businessUser;
|
|
130
|
+
const BusinessUser = yield (0, business_user_1.buildBusinessUser)(mongoose);
|
|
131
|
+
businessUser = yield BusinessUser.findOne({
|
|
132
|
+
authId: req.currentAuth.id,
|
|
133
|
+
});
|
|
134
|
+
if (!businessUser) {
|
|
135
|
+
throw new Error();
|
|
136
|
+
}
|
|
137
|
+
if ((businessUser === null || businessUser === void 0 ? void 0 : businessUser.kycStatus) !== kyc_status_1.KYCStatus.businessApproved) {
|
|
138
|
+
missingKYC = true;
|
|
139
|
+
throw new Error();
|
|
140
|
+
}
|
|
141
|
+
if ((_g = businessUser.attributes) === null || _g === void 0 ? void 0 : _g.includes(user_attribute_1.UserAttribute.broker)) {
|
|
142
|
+
throw new not_broker_error_1.NotBrokerError();
|
|
143
|
+
}
|
|
144
|
+
const user = businessUser;
|
|
145
|
+
if (user) {
|
|
146
|
+
req.user = user;
|
|
147
|
+
}
|
|
148
|
+
}
|
|
127
149
|
if ((!req.currentAdminAuth && !req.currentAuth && !req.user) ||
|
|
128
150
|
(req.currentAuth &&
|
|
129
151
|
!authorizationTypes.includes(authorization_type_1.AuthorizationType.Auth) &&
|
|
@@ -133,12 +155,12 @@ const authorize = (req, res, next, mongoose, authorizationTypes) => __awaiter(vo
|
|
|
133
155
|
}
|
|
134
156
|
if ((authorizationTypes.includes(authorization_type_1.AuthorizationType.User) ||
|
|
135
157
|
authorizationTypes.includes(authorization_type_1.AuthorizationType.UserNoKYC)) &&
|
|
136
|
-
((
|
|
158
|
+
((_h = req.cookies) === null || _h === void 0 ? void 0 : _h.jwt)) {
|
|
137
159
|
throw new missing_user_error_1.MissingUserError();
|
|
138
160
|
}
|
|
139
161
|
if (authorizationTypes.includes(authorization_type_1.AuthorizationType.Admin) &&
|
|
140
162
|
authorizationTypes.length === 1 &&
|
|
141
|
-
((
|
|
163
|
+
((_j = req.cookies) === null || _j === void 0 ? void 0 : _j.jwt)) {
|
|
142
164
|
throw new admin_only_error_1.AdminOnlyError();
|
|
143
165
|
}
|
|
144
166
|
throw new not_authorized_error_1.NotAuthorizedError();
|