@riocrypto/common-server 1.0.1255 → 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.
@@ -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, _e;
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
- let admin;
71
- try {
72
- const Admin = yield (0, admin_1.buildAdmin)(mongoose);
73
- admin = yield Admin.findOne({
74
- authIds: { $in: [(_b = req.adminAuth) === null || _b === void 0 ? void 0 : _b.id] },
75
- });
76
- console.log("req.adminAuth?.id", (_c = req.adminAuth) === null || _c === void 0 ? void 0 : _c.id);
77
- console.log("admin is ", admin);
78
- if (admin) {
79
- req.admin = admin;
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 ((_d = req.cookies) === null || _d === void 0 ? void 0 : _d.accessToken) {
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
- try {
119
- const User = yield (0, user_1.buildUser)(mongoose);
120
- const user = yield User.findOne({
121
- authIds: { $in: [(_e = req.auth) === null || _e === void 0 ? void 0 : _e.id] },
122
- });
123
- if (user) {
124
- if (authorizationTypes.includes(common_1.AuthorizationType.UserNoKYC)) {
125
- req.user = user;
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();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@riocrypto/common-server",
3
- "version": "1.0.1255",
3
+ "version": "1.0.1256",
4
4
  "description": "",
5
5
  "main": "./build/index.js",
6
6
  "types": "./build/index.d.ts",