@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.
@@ -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
- 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
- if (admin) {
77
- 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
+ }
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
- try {
117
- const User = yield (0, user_1.buildUser)(mongoose);
118
- const user = yield User.findOne({
119
- authIds: { $in: [(_d = req.auth) === null || _d === void 0 ? void 0 : _d.id] },
120
- });
121
- if (user) {
122
- if (authorizationTypes.includes(common_1.AuthorizationType.UserNoKYC)) {
123
- req.user = user;
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();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@riocrypto/common-server",
3
- "version": "1.0.1254",
3
+ "version": "1.0.1256",
4
4
  "description": "",
5
5
  "main": "./build/index.js",
6
6
  "types": "./build/index.d.ts",