@riocrypto/common 1.0.397 → 1.0.399
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 -14
- package/package.json +1 -1
|
@@ -22,11 +22,23 @@ const not_authorized_error_1 = require("../errors/not-authorized-error");
|
|
|
22
22
|
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
|
+
const missing_password_error_1 = require("../errors/missing-password-error");
|
|
26
|
+
const missing_security_question_error_1 = require("../errors/missing-security-question-error");
|
|
25
27
|
const authorize = (req, res, next, mongoose, authorizationTypes) => __awaiter(void 0, void 0, void 0, function* () {
|
|
26
|
-
var _a, _b, _c;
|
|
28
|
+
var _a, _b, _c, _d, _e, _f, _g;
|
|
27
29
|
let missingKYC = false;
|
|
30
|
+
if (authorizationTypes.includes(authorization_type_1.AuthorizationType.Auth) ||
|
|
31
|
+
authorizationTypes.includes(authorization_type_1.AuthorizationType.UserNoKYC) ||
|
|
32
|
+
authorizationTypes.includes(authorization_type_1.AuthorizationType.User)) {
|
|
33
|
+
if ((_b = (_a = req.currentAuth) === null || _a === void 0 ? void 0 : _a.missing) === null || _b === void 0 ? void 0 : _b.includes("password")) {
|
|
34
|
+
throw new missing_password_error_1.MissingPasswordError();
|
|
35
|
+
}
|
|
36
|
+
if ((_d = (_c = req.currentAuth) === null || _c === void 0 ? void 0 : _c.missing) === null || _d === void 0 ? void 0 : _d.includes("securityQuestion")) {
|
|
37
|
+
throw new missing_security_question_error_1.MissingSecurityQuestionError();
|
|
38
|
+
}
|
|
39
|
+
}
|
|
28
40
|
if (authorizationTypes.includes(authorization_type_1.AuthorizationType.Auth)) {
|
|
29
|
-
if ((
|
|
41
|
+
if ((_e = req.cookies) === null || _e === void 0 ? void 0 : _e.jwt) {
|
|
30
42
|
try {
|
|
31
43
|
const payload = jsonwebtoken_1.default.verify(req.cookies.jwt, process.env.JWT_KEY);
|
|
32
44
|
req.currentAuth = payload;
|
|
@@ -35,7 +47,7 @@ const authorize = (req, res, next, mongoose, authorizationTypes) => __awaiter(vo
|
|
|
35
47
|
}
|
|
36
48
|
}
|
|
37
49
|
if (authorizationTypes.includes(authorization_type_1.AuthorizationType.Admin)) {
|
|
38
|
-
if ((
|
|
50
|
+
if ((_f = req.cookies) === null || _f === void 0 ? void 0 : _f.adminJwt) {
|
|
39
51
|
try {
|
|
40
52
|
const payload = jsonwebtoken_1.default.verify(req.cookies.adminJwt, process.env.JWT_KEY_ADMIN);
|
|
41
53
|
req.currentAdminAuth = payload;
|
|
@@ -52,6 +64,9 @@ const authorize = (req, res, next, mongoose, authorizationTypes) => __awaiter(vo
|
|
|
52
64
|
phoneNumber: req.currentAuth.phoneNumber,
|
|
53
65
|
attributes: { $ne: user_attribute_1.UserAttribute.deleted },
|
|
54
66
|
});
|
|
67
|
+
if (!individualUser) {
|
|
68
|
+
throw new missing_user_error_1.MissingUserError();
|
|
69
|
+
}
|
|
55
70
|
}
|
|
56
71
|
catch (err) {
|
|
57
72
|
individualUser = null;
|
|
@@ -62,6 +77,9 @@ const authorize = (req, res, next, mongoose, authorizationTypes) => __awaiter(vo
|
|
|
62
77
|
phoneNumber: req.currentAuth.phoneNumber,
|
|
63
78
|
attributes: { $ne: user_attribute_1.UserAttribute.deleted },
|
|
64
79
|
});
|
|
80
|
+
if (!businessUser) {
|
|
81
|
+
throw new missing_user_error_1.MissingUserError();
|
|
82
|
+
}
|
|
65
83
|
}
|
|
66
84
|
catch (err) {
|
|
67
85
|
businessUser = null;
|
|
@@ -107,21 +125,13 @@ const authorize = (req, res, next, mongoose, authorizationTypes) => __awaiter(vo
|
|
|
107
125
|
req.user = user;
|
|
108
126
|
}
|
|
109
127
|
}
|
|
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
|
-
throw new missing_user_error_1.MissingUserError();
|
|
119
|
-
}
|
|
120
|
-
}
|
|
121
128
|
if (!req.currentAdminAuth && !req.currentAuth && !req.user) {
|
|
122
129
|
if (missingKYC) {
|
|
123
130
|
throw new missing_kyc_approval_error_1.MissingKYCApprovalError();
|
|
124
131
|
}
|
|
132
|
+
if ((_g = req.cookies) === null || _g === void 0 ? void 0 : _g.jwt) {
|
|
133
|
+
throw new missing_user_error_1.MissingUserError();
|
|
134
|
+
}
|
|
125
135
|
throw new not_authorized_error_1.NotAuthorizedError();
|
|
126
136
|
}
|
|
127
137
|
next();
|