biz-slide-core 1.2.40 → 1.2.42
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/middleware/authentication.js +43 -1
- package/package.json +1 -1
@@ -58,7 +58,7 @@ var __rest = (this && this.__rest) || function (s, e) {
|
|
58
58
|
return t;
|
59
59
|
};
|
60
60
|
Object.defineProperty(exports, "__esModule", { value: true });
|
61
|
-
exports.authorizeWithSlideApp = exports.authorize = void 0;
|
61
|
+
exports.nonAuthorizeWithSlideApp = exports.authorizeWithSlideApp = exports.authorize = void 0;
|
62
62
|
var utilities_1 = require("../utilities");
|
63
63
|
var entity_1 = require("../entity");
|
64
64
|
var authorize = function (roles) {
|
@@ -136,3 +136,45 @@ var authorizeWithSlideApp = function () {
|
|
136
136
|
};
|
137
137
|
};
|
138
138
|
exports.authorizeWithSlideApp = authorizeWithSlideApp;
|
139
|
+
var nonAuthorizeWithSlideApp = function () {
|
140
|
+
return function (req, res, next) {
|
141
|
+
var _a;
|
142
|
+
return __awaiter(this, void 0, void 0, function () {
|
143
|
+
var ipAddress, sessionId, userId, token;
|
144
|
+
return __generator(this, function (_b) {
|
145
|
+
switch (_b.label) {
|
146
|
+
case 0:
|
147
|
+
ipAddress = req.headers['x-forwarded-for'] || req.connection.remoteAddress;
|
148
|
+
sessionId = req.headers['x-fingerprint-key'];
|
149
|
+
userId = "guest";
|
150
|
+
if (!req.headers.authorization) return [3 /*break*/, 2];
|
151
|
+
return [4 /*yield*/, (0, utilities_1.verifyUid)(req.headers.authorization)];
|
152
|
+
case 1:
|
153
|
+
token = _b.sent();
|
154
|
+
if (!token) {
|
155
|
+
return [2 /*return*/, res.status(401).json({ message: 'Session Expired' })];
|
156
|
+
}
|
157
|
+
userId = (token === null || token === void 0 ? void 0 : token.customer_id) || ((_a = token === null || token === void 0 ? void 0 : token.value) === null || _a === void 0 ? void 0 : _a.email);
|
158
|
+
if (!userId) {
|
159
|
+
return [2 /*return*/, res.status(401).json({ message: 'userId not found' })];
|
160
|
+
}
|
161
|
+
return [3 /*break*/, 3];
|
162
|
+
case 2:
|
163
|
+
if (!ipAddress || !sessionId) {
|
164
|
+
return [2 /*return*/, res.status(401).json({ message: 'We are not able to track your actions' })];
|
165
|
+
}
|
166
|
+
_b.label = 3;
|
167
|
+
case 3:
|
168
|
+
req.user = {
|
169
|
+
userId: userId,
|
170
|
+
sessionId: sessionId,
|
171
|
+
ipAddress: ipAddress
|
172
|
+
};
|
173
|
+
next();
|
174
|
+
return [2 /*return*/];
|
175
|
+
}
|
176
|
+
});
|
177
|
+
});
|
178
|
+
};
|
179
|
+
};
|
180
|
+
exports.nonAuthorizeWithSlideApp = nonAuthorizeWithSlideApp;
|