@riocrypto/common-server 1.0.1216 → 1.0.1217
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 +14 -11
- package/package.json +2 -2
|
@@ -19,9 +19,10 @@ const common_1 = require("@riocrypto/common");
|
|
|
19
19
|
const auth_1 = require("../models/auth");
|
|
20
20
|
const apiKey_1 = require("../services/apiKey");
|
|
21
21
|
const secret_manager_client_1 = require("../clients/secret-manager-client");
|
|
22
|
+
const admin_1 = require("../models/admin");
|
|
22
23
|
const admin_auth_1 = require("../models/admin-auth");
|
|
23
24
|
const authorize = (req, res, next, mongoose, authorizationTypes) => __awaiter(void 0, void 0, void 0, function* () {
|
|
24
|
-
var _a, _b, _c
|
|
25
|
+
var _a, _b, _c;
|
|
25
26
|
if (authorizationTypes.includes(common_1.AuthorizationType.Cluster)) {
|
|
26
27
|
let apiKey = req.header("x-cluster-api-key");
|
|
27
28
|
const CLUSTER_API_KEY = yield secret_manager_client_1.secretManagerClient.getSecretValue("CLUSTER_API_KEY");
|
|
@@ -67,17 +68,19 @@ const authorize = (req, res, next, mongoose, authorizationTypes) => __awaiter(vo
|
|
|
67
68
|
}
|
|
68
69
|
}
|
|
69
70
|
if (authorizationTypes.includes(common_1.AuthorizationType.Admin)) {
|
|
70
|
-
if (
|
|
71
|
+
if (req.currentAdminAuth) {
|
|
72
|
+
let admin;
|
|
71
73
|
try {
|
|
72
|
-
const
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
}
|
|
76
|
-
const payload = jsonwebtoken_1.default.verify(req.cookies.adminAccessToken, ADMIN_ACCESS_TOKEN_SECRET);
|
|
77
|
-
req.currentAdminAuth = payload;
|
|
74
|
+
const Admin = yield (0, admin_1.buildAdmin)(mongoose);
|
|
75
|
+
admin = yield Admin.findOne({
|
|
76
|
+
authIds: { $in: [req.currentAdminAuth.id] },
|
|
77
|
+
});
|
|
78
78
|
}
|
|
79
79
|
catch (err) {
|
|
80
|
-
|
|
80
|
+
admin = null;
|
|
81
|
+
}
|
|
82
|
+
if (admin) {
|
|
83
|
+
req.admin = admin;
|
|
81
84
|
}
|
|
82
85
|
}
|
|
83
86
|
}
|
|
@@ -104,7 +107,7 @@ const authorize = (req, res, next, mongoose, authorizationTypes) => __awaiter(vo
|
|
|
104
107
|
console.log(err);
|
|
105
108
|
}
|
|
106
109
|
}
|
|
107
|
-
else if ((
|
|
110
|
+
else if ((_b = req.cookies) === null || _b === void 0 ? void 0 : _b.accessToken) {
|
|
108
111
|
try {
|
|
109
112
|
const ACCESS_TOKEN_SECRET = yield secret_manager_client_1.secretManagerClient.getSecretValue("ACCESS_TOKEN_SECRET");
|
|
110
113
|
if (!ACCESS_TOKEN_SECRET) {
|
|
@@ -131,7 +134,7 @@ const authorize = (req, res, next, mongoose, authorizationTypes) => __awaiter(vo
|
|
|
131
134
|
if (user) {
|
|
132
135
|
req.user = user;
|
|
133
136
|
}
|
|
134
|
-
if (((
|
|
137
|
+
if (((_c = req.user) === null || _c === void 0 ? void 0 : _c.kycStatus) !== common_1.KYCStatus.Approved &&
|
|
135
138
|
authorizationTypes.includes(common_1.AuthorizationType.User)) {
|
|
136
139
|
throw new common_1.MissingKYCApprovalError();
|
|
137
140
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@riocrypto/common-server",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.1217",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "./build/index.js",
|
|
6
6
|
"types": "./build/index.d.ts",
|
|
@@ -26,7 +26,7 @@
|
|
|
26
26
|
"@aws-sdk/client-s3": "^3.297.0",
|
|
27
27
|
"@everapi/currencyapi-js": "^1.0.6",
|
|
28
28
|
"@google-cloud/storage": "^6.9.5",
|
|
29
|
-
"@riocrypto/common": "^1.0.
|
|
29
|
+
"@riocrypto/common": "^1.0.1114",
|
|
30
30
|
"@types/express": "^4.17.13",
|
|
31
31
|
"axios": "^0.27.2",
|
|
32
32
|
"ccxt": "^3.0.30",
|