@riocrypto/common-server 1.0.1254 → 1.0.1256
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 +25 -21
- package/package.json +1 -1
|
@@ -67,17 +67,19 @@ const authorize = (req, res, next, mongoose, authorizationTypes) => __awaiter(vo
|
|
|
67
67
|
}
|
|
68
68
|
}
|
|
69
69
|
if (authorizationTypes.includes(common_1.AuthorizationType.Admin)) {
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
70
|
+
if (req.adminAuth) {
|
|
71
|
+
let admin;
|
|
72
|
+
try {
|
|
73
|
+
const Admin = yield (0, admin_1.buildAdmin)(mongoose);
|
|
74
|
+
admin = yield Admin.findOne({
|
|
75
|
+
authIds: { $in: [(_b = req.adminAuth) === null || _b === void 0 ? void 0 : _b.id] },
|
|
76
|
+
});
|
|
77
|
+
if (admin) {
|
|
78
|
+
req.admin = admin;
|
|
79
|
+
}
|
|
78
80
|
}
|
|
81
|
+
catch (err) { }
|
|
79
82
|
}
|
|
80
|
-
catch (err) { }
|
|
81
83
|
}
|
|
82
84
|
if (authorizationTypes.includes(common_1.AuthorizationType.Auth) ||
|
|
83
85
|
authorizationTypes.includes(common_1.AuthorizationType.UserNoKYC) ||
|
|
@@ -113,23 +115,25 @@ const authorize = (req, res, next, mongoose, authorizationTypes) => __awaiter(vo
|
|
|
113
115
|
}
|
|
114
116
|
if (authorizationTypes.includes(common_1.AuthorizationType.UserNoKYC) ||
|
|
115
117
|
authorizationTypes.includes(common_1.AuthorizationType.User)) {
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
if (
|
|
123
|
-
|
|
124
|
-
}
|
|
125
|
-
else {
|
|
126
|
-
if (user.kycStatus === common_1.KYCStatus.Approved) {
|
|
118
|
+
if (req.auth) {
|
|
119
|
+
try {
|
|
120
|
+
const User = yield (0, user_1.buildUser)(mongoose);
|
|
121
|
+
const user = yield User.findOne({
|
|
122
|
+
authIds: { $in: [(_d = req.auth) === null || _d === void 0 ? void 0 : _d.id] },
|
|
123
|
+
});
|
|
124
|
+
if (user) {
|
|
125
|
+
if (authorizationTypes.includes(common_1.AuthorizationType.UserNoKYC)) {
|
|
127
126
|
req.user = user;
|
|
128
127
|
}
|
|
128
|
+
else {
|
|
129
|
+
if (user.kycStatus === common_1.KYCStatus.Approved) {
|
|
130
|
+
req.user = user;
|
|
131
|
+
}
|
|
132
|
+
}
|
|
129
133
|
}
|
|
130
134
|
}
|
|
135
|
+
catch (err) { }
|
|
131
136
|
}
|
|
132
|
-
catch (err) { }
|
|
133
137
|
}
|
|
134
138
|
if (authorizationTypes.includes(common_1.AuthorizationType.Public)) {
|
|
135
139
|
next();
|