@riocrypto/common 1.0.432 → 1.0.433
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.
- package/build/middlewares/authorize.js +24 -18
- package/package.json +1 -1
|
@@ -27,7 +27,7 @@ const missing_security_question_error_1 = require("../errors/missing-security-qu
|
|
|
27
27
|
const admin_only_error_1 = require("../errors/admin-only-error");
|
|
28
28
|
const not_broker_error_1 = require("../errors/not-broker-error");
|
|
29
29
|
const authorize = (req, res, next, mongoose, authorizationTypes) => __awaiter(void 0, void 0, void 0, function* () {
|
|
30
|
-
var _a, _b, _c, _d, _e, _f, _g, _h
|
|
30
|
+
var _a, _b, _c, _d, _e, _f, _g, _h;
|
|
31
31
|
let missingKYC = false;
|
|
32
32
|
if (authorizationTypes.includes(authorization_type_1.AuthorizationType.Auth) ||
|
|
33
33
|
authorizationTypes.includes(authorization_type_1.AuthorizationType.UserNoKYC) ||
|
|
@@ -126,22 +126,25 @@ const authorize = (req, res, next, mongoose, authorizationTypes) => __awaiter(vo
|
|
|
126
126
|
}
|
|
127
127
|
}
|
|
128
128
|
if (authorizationTypes.includes(authorization_type_1.AuthorizationType.Broker)) {
|
|
129
|
-
let
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
129
|
+
let brokerBusinessUser;
|
|
130
|
+
try {
|
|
131
|
+
const BusinessUser = yield (0, business_user_1.buildBusinessUser)(mongoose);
|
|
132
|
+
brokerBusinessUser = yield BusinessUser.findOne({
|
|
133
|
+
authId: req.currentAuth.id,
|
|
134
|
+
attributes: { $e: user_attribute_1.UserAttribute.broker },
|
|
135
|
+
});
|
|
136
|
+
if (!brokerBusinessUser) {
|
|
137
|
+
throw new Error();
|
|
138
|
+
}
|
|
139
|
+
if ((brokerBusinessUser === null || brokerBusinessUser === void 0 ? void 0 : brokerBusinessUser.kycStatus) !== kyc_status_1.KYCStatus.businessApproved) {
|
|
140
|
+
missingKYC = true;
|
|
141
|
+
throw new Error();
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
catch (err) {
|
|
145
|
+
brokerBusinessUser = null;
|
|
143
146
|
}
|
|
144
|
-
const user =
|
|
147
|
+
const user = brokerBusinessUser;
|
|
145
148
|
if (user) {
|
|
146
149
|
req.user = user;
|
|
147
150
|
}
|
|
@@ -155,14 +158,17 @@ const authorize = (req, res, next, mongoose, authorizationTypes) => __awaiter(vo
|
|
|
155
158
|
}
|
|
156
159
|
if ((authorizationTypes.includes(authorization_type_1.AuthorizationType.User) ||
|
|
157
160
|
authorizationTypes.includes(authorization_type_1.AuthorizationType.UserNoKYC)) &&
|
|
158
|
-
((
|
|
161
|
+
((_g = req.cookies) === null || _g === void 0 ? void 0 : _g.jwt)) {
|
|
159
162
|
throw new missing_user_error_1.MissingUserError();
|
|
160
163
|
}
|
|
161
164
|
if (authorizationTypes.includes(authorization_type_1.AuthorizationType.Admin) &&
|
|
162
165
|
authorizationTypes.length === 1 &&
|
|
163
|
-
((
|
|
166
|
+
((_h = req.cookies) === null || _h === void 0 ? void 0 : _h.jwt)) {
|
|
164
167
|
throw new admin_only_error_1.AdminOnlyError();
|
|
165
168
|
}
|
|
169
|
+
if (!req.user && authorizationTypes.includes(authorization_type_1.AuthorizationType.Broker)) {
|
|
170
|
+
throw new not_broker_error_1.NotBrokerError();
|
|
171
|
+
}
|
|
166
172
|
throw new not_authorized_error_1.NotAuthorizedError();
|
|
167
173
|
}
|
|
168
174
|
next();
|