@konplit-services/common 1.13.0 → 1.14.0
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.
|
@@ -9,13 +9,18 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
9
9
|
});
|
|
10
10
|
};
|
|
11
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
-
exports.TwoFactorSessionValidation = void 0;
|
|
12
|
+
exports.TwoFactorSessionValidation = exports.expiredTime = void 0;
|
|
13
13
|
const Jwt_1 = require("../services/Jwt");
|
|
14
14
|
const notAuthorized_1 = require("../errors/notAuthorized");
|
|
15
15
|
const error_codes_1 = require("../helper/errorCodes/error-codes");
|
|
16
16
|
const app_configs_1 = require("../app.configs");
|
|
17
17
|
const helper_1 = require("../helper");
|
|
18
18
|
const redis_1 = require("../redis");
|
|
19
|
+
const expiredTime = (expires) => {
|
|
20
|
+
const expiryTime = expires - Math.floor(Date.now() / 1000);
|
|
21
|
+
return expiryTime;
|
|
22
|
+
};
|
|
23
|
+
exports.expiredTime = expiredTime;
|
|
19
24
|
const TwoFactorSessionValidation = (req, res, next) => __awaiter(void 0, void 0, void 0, function* () {
|
|
20
25
|
if (!req.headers["k-2fa-session"]) {
|
|
21
26
|
throw new notAuthorized_1.NotAuthorizedError("k-2fa-session token not provided", error_codes_1.error_codes.INVALID_AUTHORIZATION);
|
|
@@ -29,7 +34,7 @@ const TwoFactorSessionValidation = (req, res, next) => __awaiter(void 0, void 0,
|
|
|
29
34
|
if (isValidToken) {
|
|
30
35
|
throw new notAuthorized_1.NotAuthorizedError(helper_1.lang.not_authorized, error_codes_1.error_codes.INVALID_AUTHORIZATION);
|
|
31
36
|
}
|
|
32
|
-
yield redis_1.redisWrapper.
|
|
37
|
+
yield redis_1.redisWrapper.revokeToken((0, redis_1.setsetRevokedToken)(payload.userId, token), (0, exports.expiredTime)(payload.exp));
|
|
33
38
|
req.twoFaData = payload;
|
|
34
39
|
}
|
|
35
40
|
return next();
|