@misalon/common 1.0.15 → 1.0.16
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.
@@ -6,15 +6,22 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.currentUser = void 0;
|
7
7
|
var jsonwebtoken_1 = __importDefault(require("jsonwebtoken"));
|
8
8
|
var currentUser = function (req, res, next) {
|
9
|
-
var _a;
|
10
|
-
|
11
|
-
|
9
|
+
var _a, _b;
|
10
|
+
console.log('Session JWT:', (_a = req.session) === null || _a === void 0 ? void 0 : _a.jwt); // Log the JWT from session
|
11
|
+
if (!((_b = req.session) === null || _b === void 0 ? void 0 : _b.jwt)) {
|
12
|
+
console.log('No JWT in session, skipping user authentication');
|
13
|
+
return next(); // No JWT in session, move to the next middleware
|
12
14
|
}
|
13
15
|
try {
|
16
|
+
// Log before decoding
|
17
|
+
console.log('Attempting to decode JWT...');
|
14
18
|
var payload = jsonwebtoken_1.default.verify(req.session.jwt, process.env.JWT_KEY);
|
15
|
-
|
19
|
+
console.log('Decoded JWT Payload:', payload); // Log the decoded payload
|
20
|
+
req.currentUser = payload; // Attach user information to request
|
16
21
|
}
|
17
|
-
catch (err) {
|
18
|
-
|
22
|
+
catch (err) {
|
23
|
+
console.error('Error decoding JWT:', err); // Log any decoding errors
|
24
|
+
}
|
25
|
+
next(); // Proceed to the next middleware or route handler
|
19
26
|
};
|
20
27
|
exports.currentUser = currentUser;
|