@common_ch/common 1.0.226 → 1.0.227

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.
@@ -5,6 +5,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.currentUser = void 0;
7
7
  const jsonwebtoken_1 = __importDefault(require("jsonwebtoken"));
8
+ const redis_service_1 = require("../services/redis/redis.service");
8
9
  const currentUser = (req, res, next) => {
9
10
  const authHeader = req.headers['authorization'];
10
11
  if (!authHeader || !authHeader.startsWith('Bearer')) {
@@ -12,8 +13,16 @@ const currentUser = (req, res, next) => {
12
13
  }
13
14
  try {
14
15
  const token = authHeader.split(' ')[1];
15
- const payload = jsonwebtoken_1.default.verify(token, process.env.JWT_KEY);
16
- req.currentUser = payload;
16
+ (0, redis_service_1.getCache)(token).then((result) => {
17
+ if (result) {
18
+ console.log('user blocked.');
19
+ next();
20
+ }
21
+ else {
22
+ const payload = jsonwebtoken_1.default.verify(token, process.env.JWT_KEY);
23
+ req.currentUser = payload;
24
+ }
25
+ });
17
26
  }
18
27
  catch (err) { }
19
28
  next();
@@ -0,0 +1,3 @@
1
+ export declare function setCache(key: string, value: any, ttlInSeconds?: number): Promise<void>;
2
+ export declare function getCache(key: string): Promise<string | null>;
3
+ export declare function delCache(key: string): Promise<void>;
@@ -0,0 +1,33 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.setCache = setCache;
13
+ exports.getCache = getCache;
14
+ exports.delCache = delCache;
15
+ const redisClient_1 = require("./redisClient");
16
+ function setCache(key_1, value_1) {
17
+ return __awaiter(this, arguments, void 0, function* (key, value, ttlInSeconds = 60 * 60 * 24) {
18
+ yield redisClient_1.redisClient.set(key, value, {
19
+ EX: ttlInSeconds,
20
+ });
21
+ });
22
+ }
23
+ function getCache(key) {
24
+ return __awaiter(this, void 0, void 0, function* () {
25
+ const data = yield redisClient_1.redisClient.get(key);
26
+ return data;
27
+ });
28
+ }
29
+ function delCache(key) {
30
+ return __awaiter(this, void 0, void 0, function* () {
31
+ yield redisClient_1.redisClient.del(key);
32
+ });
33
+ }