@misalon/common 1.0.16 → 1.0.17
Sign up to get free protection for your applications and to get access to all the features.
@@ -7,21 +7,19 @@ exports.currentUser = void 0;
|
|
7
7
|
var jsonwebtoken_1 = __importDefault(require("jsonwebtoken"));
|
8
8
|
var currentUser = function (req, res, next) {
|
9
9
|
var _a, _b;
|
10
|
-
console.log('Session JWT:', (_a = req.session) === null || _a === void 0 ? void 0 : _a.jwt); // Log
|
10
|
+
console.log('[auth] Session JWT:', (_a = req.session) === null || _a === void 0 ? void 0 : _a.jwt); // Log session JWT
|
11
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();
|
12
|
+
console.log('[auth] No JWT in session, skipping user authentication');
|
13
|
+
return next();
|
14
14
|
}
|
15
15
|
try {
|
16
|
-
// Log before decoding
|
17
|
-
console.log('Attempting to decode JWT...');
|
18
16
|
var payload = jsonwebtoken_1.default.verify(req.session.jwt, process.env.JWT_KEY);
|
19
|
-
|
20
|
-
req.currentUser
|
17
|
+
req.currentUser = payload;
|
18
|
+
console.log('[auth] Current User:', req.currentUser);
|
21
19
|
}
|
22
20
|
catch (err) {
|
23
|
-
console.error('Error decoding JWT:', err);
|
21
|
+
console.error('[auth] Error decoding JWT:', err);
|
24
22
|
}
|
25
|
-
next();
|
23
|
+
next();
|
26
24
|
};
|
27
25
|
exports.currentUser = currentUser;
|