biz-slide-core 1.2.40 → 1.2.41
Sign up to get free protection for your applications and to get access to all the features.
- package/middleware/authentication.js +38 -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,40 @@ 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
|
+
_b.label = 2;
|
162
|
+
case 2:
|
163
|
+
req.user = {
|
164
|
+
userId: userId,
|
165
|
+
sessionId: sessionId,
|
166
|
+
ipAddress: ipAddress
|
167
|
+
};
|
168
|
+
next();
|
169
|
+
return [2 /*return*/];
|
170
|
+
}
|
171
|
+
});
|
172
|
+
});
|
173
|
+
};
|
174
|
+
};
|
175
|
+
exports.nonAuthorizeWithSlideApp = nonAuthorizeWithSlideApp;
|