@riocrypto/common-server 1.0.537 → 1.0.538
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.
|
@@ -18,6 +18,8 @@ const user_1 = require("../models/user");
|
|
|
18
18
|
const jsonwebtoken_1 = __importDefault(require("jsonwebtoken"));
|
|
19
19
|
const partner_1 = require("../models/partner");
|
|
20
20
|
const common_1 = require("@riocrypto/common");
|
|
21
|
+
const auth_1 = require("../models/auth");
|
|
22
|
+
const apiKey_1 = require("../services/apiKey");
|
|
21
23
|
const authorize = (req, res, next, mongoose, authorizationTypes) => __awaiter(void 0, void 0, void 0, function* () {
|
|
22
24
|
var _a, _b, _c, _d, _e, _f, _g, _h;
|
|
23
25
|
let missingKYC = false;
|
|
@@ -33,7 +35,33 @@ const authorize = (req, res, next, mongoose, authorizationTypes) => __awaiter(vo
|
|
|
33
35
|
authorizationTypes.includes(common_1.AuthorizationType.UserOptional) ||
|
|
34
36
|
authorizationTypes.includes(common_1.AuthorizationType.Broker) ||
|
|
35
37
|
authorizationTypes.includes(common_1.AuthorizationType.Partner)) {
|
|
36
|
-
|
|
38
|
+
const apiKey = req.header("x-api-key");
|
|
39
|
+
if (apiKey) {
|
|
40
|
+
try {
|
|
41
|
+
const hashedApiKey = yield apiKey_1.ApiKey.toHash(apiKey);
|
|
42
|
+
const Auth = yield (0, auth_1.buildAuth)(mongoose);
|
|
43
|
+
const auth = yield Auth.findOne({
|
|
44
|
+
apiKeys: { $in: [hashedApiKey] },
|
|
45
|
+
});
|
|
46
|
+
if (auth) {
|
|
47
|
+
const missing = [];
|
|
48
|
+
if (!auth.password) {
|
|
49
|
+
missing.push("password");
|
|
50
|
+
}
|
|
51
|
+
if (!auth.securityAnswer || !auth.securityQuestion) {
|
|
52
|
+
missing.push("securityQuestion");
|
|
53
|
+
}
|
|
54
|
+
const payload = {
|
|
55
|
+
id: auth.id,
|
|
56
|
+
phoneNumber: auth.phoneNumber,
|
|
57
|
+
missing,
|
|
58
|
+
};
|
|
59
|
+
req.currentAuth = payload;
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
catch (err) { }
|
|
63
|
+
}
|
|
64
|
+
else if ((_a = req.cookies) === null || _a === void 0 ? void 0 : _a.accessToken) {
|
|
37
65
|
try {
|
|
38
66
|
const payload = jsonwebtoken_1.default.verify(req.cookies.accessToken, process.env.JWT_KEY);
|
|
39
67
|
req.currentAuth = payload;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@riocrypto/common-server",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.538",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "./build/index.js",
|
|
6
6
|
"types": "./build/index.d.ts",
|
|
@@ -22,7 +22,7 @@
|
|
|
22
22
|
},
|
|
23
23
|
"dependencies": {
|
|
24
24
|
"@aws-sdk/client-s3": "^3.297.0",
|
|
25
|
-
"@riocrypto/common": "^1.0.
|
|
25
|
+
"@riocrypto/common": "^1.0.539",
|
|
26
26
|
"@types/express": "^4.17.13",
|
|
27
27
|
"axios": "^0.27.2",
|
|
28
28
|
"ccxt": "^3.0.30",
|