fpavon-ee-shared 1.0.13 → 1.0.15
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.
|
@@ -17,7 +17,13 @@ const jsonwebtoken_1 = __importDefault(require("jsonwebtoken"));
|
|
|
17
17
|
const connection_sql_1 = require("../bd/connection.sql"); // Asegúrate de ajustar la ruta a tu configuración de base de datos
|
|
18
18
|
const axios_1 = __importDefault(require("axios"));
|
|
19
19
|
function getSecret() {
|
|
20
|
-
|
|
20
|
+
const secret = process.env.SECRET;
|
|
21
|
+
if (!secret) {
|
|
22
|
+
// Lanza un error para detener la ejecución si no está configurada
|
|
23
|
+
console.error("ERROR: La variable de entorno 'SECRET' no está configurada.");
|
|
24
|
+
throw new Error("SECRET_NOT_CONFIGURED");
|
|
25
|
+
}
|
|
26
|
+
return secret;
|
|
21
27
|
}
|
|
22
28
|
const asyncHandlerWrapper = (req, res, next) => {
|
|
23
29
|
// Asume que 'fn' es tu función asíncrona original (la que tiene el Promise<void>)
|
|
@@ -37,7 +43,9 @@ const validarToken = (req, res, next) => __awaiter(void 0, void 0, void 0, funct
|
|
|
37
43
|
let token = bearer[1];
|
|
38
44
|
// Limpio el token de comillas por las dudas
|
|
39
45
|
token = token.replace(/['"]+/g, '');
|
|
40
|
-
|
|
46
|
+
const secret = getSecret();
|
|
47
|
+
console.log("SECRET: ", secret);
|
|
48
|
+
let data = jsonwebtoken_1.default.verify(token, (secret || ''));
|
|
41
49
|
const { afiliado, idNavegador } = data;
|
|
42
50
|
// Verificar si el usuario está deslogueado
|
|
43
51
|
const queryVerificar = `SELECT logueado, idNavegador FROM Usuarios WHERE afiliado = '${data.afiliado}'`;
|
|
@@ -3,8 +3,16 @@ import jwt from 'jsonwebtoken';
|
|
|
3
3
|
import { getConnection } from '../bd/connection.sql'; // Asegúrate de ajustar la ruta a tu configuración de base de datos
|
|
4
4
|
import axios from 'axios';
|
|
5
5
|
|
|
6
|
-
function getSecret(){
|
|
7
|
-
|
|
6
|
+
function getSecret(): string {
|
|
7
|
+
const secret = process.env.SECRET;
|
|
8
|
+
|
|
9
|
+
if (!secret) {
|
|
10
|
+
// Lanza un error para detener la ejecución si no está configurada
|
|
11
|
+
console.error("ERROR: La variable de entorno 'SECRET' no está configurada.");
|
|
12
|
+
throw new Error("SECRET_NOT_CONFIGURED");
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
return secret;
|
|
8
16
|
}
|
|
9
17
|
|
|
10
18
|
const asyncHandlerWrapper: RequestHandler = (req: Request, res: Response, next: NextFunction) => {
|
|
@@ -28,7 +36,9 @@ const validarToken = async (req: Request, res: Response, next: NextFunction): Pr
|
|
|
28
36
|
let token = bearer[1];
|
|
29
37
|
// Limpio el token de comillas por las dudas
|
|
30
38
|
token = token.replace(/['"]+/g, '');
|
|
31
|
-
|
|
39
|
+
const secret = getSecret();
|
|
40
|
+
console.log("SECRET: ", secret)
|
|
41
|
+
let data: any = jwt.verify(token, (secret || ''));
|
|
32
42
|
const { afiliado, idNavegador } = data;
|
|
33
43
|
|
|
34
44
|
// Verificar si el usuario está deslogueado
|