@jpbs/common 1.2.2 → 1.2.3
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/build/redisClient.d.ts +2 -2
- package/build/redisClient.js +5 -15
- package/package.json +1 -1
package/build/redisClient.d.ts
CHANGED
@@ -289,6 +289,6 @@ declare const redisClient: import("@redis/client").RedisClientType<{
|
|
289
289
|
};
|
290
290
|
} & import("redis").RedisModules, import("redis").RedisFunctions, import("redis").RedisScripts>;
|
291
291
|
declare const initializeRedis: () => Promise<void>;
|
292
|
-
declare const revokeToken: (token: string) => Promise<void>;
|
293
|
-
declare const isTokenRevoked: (token: string) => Promise<boolean>;
|
292
|
+
declare const revokeToken: (token: string, userId: string) => Promise<void>;
|
293
|
+
declare const isTokenRevoked: (token: string, userId: string) => Promise<boolean>;
|
294
294
|
export { redisClient, initializeRedis, revokeToken, isTokenRevoked };
|
package/build/redisClient.js
CHANGED
@@ -46,17 +46,12 @@ const getTokenTTL = (token) => {
|
|
46
46
|
return 0;
|
47
47
|
}
|
48
48
|
};
|
49
|
-
const revokeToken = (token) => __awaiter(void 0, void 0, void 0, function* () {
|
49
|
+
const revokeToken = (token, userId) => __awaiter(void 0, void 0, void 0, function* () {
|
50
50
|
try {
|
51
|
-
const decoded = jsonwebtoken_1.default.decode(token);
|
52
|
-
if (!decoded || !decoded.id) {
|
53
|
-
console.error('❌ Token does not contain user id');
|
54
|
-
return;
|
55
|
-
}
|
56
51
|
const ttl = getTokenTTL(token);
|
57
52
|
if (ttl > 0) {
|
58
|
-
yield redisClient.set(`revokedToken:${
|
59
|
-
console.log(`🚫 Token revoked for user ${
|
53
|
+
yield redisClient.set(`revokedToken:${userId}:${token}`, 'revoked', { EX: ttl });
|
54
|
+
console.log(`🚫 Token revoked for user ${userId}: ${token}`);
|
60
55
|
}
|
61
56
|
else {
|
62
57
|
console.log('⚠️ Token already expired, no need to revoke.');
|
@@ -67,14 +62,9 @@ const revokeToken = (token) => __awaiter(void 0, void 0, void 0, function* () {
|
|
67
62
|
}
|
68
63
|
});
|
69
64
|
exports.revokeToken = revokeToken;
|
70
|
-
const isTokenRevoked = (token) => __awaiter(void 0, void 0, void 0, function* () {
|
65
|
+
const isTokenRevoked = (token, userId) => __awaiter(void 0, void 0, void 0, function* () {
|
71
66
|
try {
|
72
|
-
const
|
73
|
-
if (!decoded || !decoded.id) {
|
74
|
-
console.error('❌ Token does not contain user id');
|
75
|
-
return false;
|
76
|
-
}
|
77
|
-
const result = yield redisClient.get(`revokedToken:${decoded.id}:${token}`);
|
67
|
+
const result = yield redisClient.get(`revokedToken:${userId}:${token}`);
|
78
68
|
return result !== null;
|
79
69
|
}
|
80
70
|
catch (error) {
|