@aichatwar/shared 1.0.106 → 1.0.108
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.
|
@@ -66,9 +66,15 @@ class Listener {
|
|
|
66
66
|
topic: this.topic,
|
|
67
67
|
fromBeginning: false,
|
|
68
68
|
});
|
|
69
|
+
// Log success message, especially if there were previous retries
|
|
70
|
+
if (this.retryCount > 0) {
|
|
71
|
+
console.log(`✅ [${this.topic}] Successfully connected after ${this.retryCount} retry attempts. Listening with groupId: ${this.groupId}`);
|
|
72
|
+
}
|
|
73
|
+
else {
|
|
74
|
+
console.log(`✅ [${this.topic}] Successfully connected. Listening to topic with groupId: ${this.groupId}`);
|
|
75
|
+
}
|
|
69
76
|
// Reset retry count on successful connection
|
|
70
77
|
this.retryCount = 0;
|
|
71
|
-
console.log(`[${this.topic}] Listening to topic with groupId: ${this.groupId}`);
|
|
72
78
|
yield this.consumer.run({
|
|
73
79
|
eachMessage: (payload) => __awaiter(this, void 0, void 0, function* () {
|
|
74
80
|
if (!payload.message.value)
|
|
@@ -8,18 +8,31 @@ const jsonwebtoken_1 = __importDefault(require("jsonwebtoken"));
|
|
|
8
8
|
;
|
|
9
9
|
const extractJWTPayload = (req, res, next) => {
|
|
10
10
|
var _a;
|
|
11
|
-
|
|
12
|
-
|
|
11
|
+
let token;
|
|
12
|
+
// First, try to get token from session (cookie-based auth for web)
|
|
13
|
+
if ((_a = req.session) === null || _a === void 0 ? void 0 : _a.jwt) {
|
|
14
|
+
token = req.session.jwt;
|
|
13
15
|
}
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
catch (error) {
|
|
20
|
-
console.log(error.message);
|
|
16
|
+
// If no session token, try to get from Authorization header (Bearer token for mobile)
|
|
17
|
+
else if (req.headers.authorization) {
|
|
18
|
+
const authHeader = req.headers.authorization;
|
|
19
|
+
if (authHeader.startsWith('Bearer ')) {
|
|
20
|
+
token = authHeader.substring(7); // Remove 'Bearer ' prefix
|
|
21
21
|
}
|
|
22
|
+
}
|
|
23
|
+
// If no token found, continue without setting jwtPayload
|
|
24
|
+
if (!token) {
|
|
22
25
|
return next();
|
|
23
26
|
}
|
|
27
|
+
// Verify and extract JWT payload
|
|
28
|
+
try {
|
|
29
|
+
const payload = jsonwebtoken_1.default.verify(token, process.env.JWT_DEV);
|
|
30
|
+
req.jwtPayload = payload;
|
|
31
|
+
}
|
|
32
|
+
catch (error) {
|
|
33
|
+
console.log(`JWT verification failed: ${error.message}`);
|
|
34
|
+
// Continue without setting jwtPayload - loginRequired middleware will handle 401
|
|
35
|
+
}
|
|
36
|
+
return next();
|
|
24
37
|
};
|
|
25
38
|
exports.extractJWTPayload = extractJWTPayload;
|