@riocrypto/common-server 1.0.1255 → 1.0.1257
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 +30 -27
- package/package.json +1 -1
|
@@ -22,7 +22,7 @@ const secret_manager_client_1 = require("../clients/secret-manager-client");
|
|
|
22
22
|
const admin_1 = require("../models/admin");
|
|
23
23
|
const admin_auth_1 = require("../models/admin-auth");
|
|
24
24
|
const authorize = (req, res, next, mongoose, authorizationTypes) => __awaiter(void 0, void 0, void 0, function* () {
|
|
25
|
-
var _a, _b, _c, _d
|
|
25
|
+
var _a, _b, _c, _d;
|
|
26
26
|
if (authorizationTypes.includes(common_1.AuthorizationType.Cluster)) {
|
|
27
27
|
let apiKey = req.header("x-cluster-api-key");
|
|
28
28
|
const CLUSTER_API_KEY = yield secret_manager_client_1.secretManagerClient.getSecretValue("CLUSTER_API_KEY");
|
|
@@ -67,19 +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
|
-
|
|
78
|
-
|
|
79
|
-
|
|
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
|
+
}
|
|
80
80
|
}
|
|
81
|
+
catch (err) { }
|
|
81
82
|
}
|
|
82
|
-
catch (err) { }
|
|
83
83
|
}
|
|
84
84
|
if (authorizationTypes.includes(common_1.AuthorizationType.Auth) ||
|
|
85
85
|
authorizationTypes.includes(common_1.AuthorizationType.UserNoKYC) ||
|
|
@@ -98,7 +98,7 @@ const authorize = (req, res, next, mongoose, authorizationTypes) => __awaiter(vo
|
|
|
98
98
|
}
|
|
99
99
|
catch (err) { }
|
|
100
100
|
}
|
|
101
|
-
else if ((
|
|
101
|
+
else if ((_c = req.cookies) === null || _c === void 0 ? void 0 : _c.accessToken) {
|
|
102
102
|
try {
|
|
103
103
|
const ACCESS_TOKEN_SECRET = yield secret_manager_client_1.secretManagerClient.getSecretValue("ACCESS_TOKEN_SECRET");
|
|
104
104
|
if (!ACCESS_TOKEN_SECRET) {
|
|
@@ -115,23 +115,25 @@ const authorize = (req, res, next, mongoose, authorizationTypes) => __awaiter(vo
|
|
|
115
115
|
}
|
|
116
116
|
if (authorizationTypes.includes(common_1.AuthorizationType.UserNoKYC) ||
|
|
117
117
|
authorizationTypes.includes(common_1.AuthorizationType.User)) {
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
if (
|
|
125
|
-
|
|
126
|
-
}
|
|
127
|
-
else {
|
|
128
|
-
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)) {
|
|
129
126
|
req.user = user;
|
|
130
127
|
}
|
|
128
|
+
else {
|
|
129
|
+
if (user.kycStatus === common_1.KYCStatus.Approved) {
|
|
130
|
+
req.user = user;
|
|
131
|
+
}
|
|
132
|
+
}
|
|
131
133
|
}
|
|
132
134
|
}
|
|
135
|
+
catch (err) { }
|
|
133
136
|
}
|
|
134
|
-
catch (err) { }
|
|
135
137
|
}
|
|
136
138
|
if (authorizationTypes.includes(common_1.AuthorizationType.Public)) {
|
|
137
139
|
next();
|
|
@@ -151,8 +153,9 @@ const authorize = (req, res, next, mongoose, authorizationTypes) => __awaiter(vo
|
|
|
151
153
|
next();
|
|
152
154
|
return;
|
|
153
155
|
}
|
|
154
|
-
if (authorizationTypes.includes(common_1.AuthorizationType.User) ||
|
|
155
|
-
|
|
156
|
+
if ((authorizationTypes.includes(common_1.AuthorizationType.User) ||
|
|
157
|
+
authorizationTypes.includes(common_1.AuthorizationType.UserNoKYC)) &&
|
|
158
|
+
req.user) {
|
|
156
159
|
next();
|
|
157
160
|
return;
|
|
158
161
|
}
|