Modificaciones
This commit is contained in:
@@ -51,9 +51,11 @@ export class QrTokenService {
|
|||||||
// Convert fecha_fin to seconds from now for expiresIn
|
// Convert fecha_fin to seconds from now for expiresIn
|
||||||
const expiresInSeconds = Math.floor((fecha_fin.getTime() - Date.now()) / 1000);
|
const expiresInSeconds = Math.floor((fecha_fin.getTime() - Date.now()) / 1000);
|
||||||
|
|
||||||
|
console.log("Caducidad token: ", Math.floor((fecha_fin.getTime() - Date.now()) / 1000));
|
||||||
|
|
||||||
return this.jwtService.sign(payload, {
|
return this.jwtService.sign(payload, {
|
||||||
secret,
|
secret,
|
||||||
expiresIn: expiresInSeconds > 0 ? expiresInSeconds : 0, // El QR puede ser válido por 30 días
|
expiresIn: expiresInSeconds > 0 ? expiresInSeconds : 3600, // El QR puede ser válido por 30 días
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -70,6 +72,7 @@ export class QrTokenService {
|
|||||||
type: string;
|
type: string;
|
||||||
iat: number;
|
iat: number;
|
||||||
} | null >{
|
} | null >{
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const secret =
|
const secret =
|
||||||
this.configService.get<string>('QR_JWT_SECRET') ||
|
this.configService.get<string>('QR_JWT_SECRET') ||
|
||||||
@@ -79,21 +82,24 @@ export class QrTokenService {
|
|||||||
|
|
||||||
const decoded = this.jwtService.verify(token, { secret });
|
const decoded = this.jwtService.verify(token, { secret });
|
||||||
|
|
||||||
|
//console.log("fecha fin:", fecha_fin2.fecha_fin);
|
||||||
|
console.log("este es el token", decoded);
|
||||||
|
|
||||||
const fecha_fin2 = await this.eventoREpo.findOne({
|
const fecha_fin2 = await this.eventoREpo.findOne({
|
||||||
where: { id_evento:decoded.id_evento },
|
where: { id_evento:decoded.id_evento },
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
if (!fecha_fin2) {
|
if (!fecha_fin2) {
|
||||||
throw new UnauthorizedException('Evento no encontrado');
|
throw new UnauthorizedException('Evento no encontrado');
|
||||||
}
|
}
|
||||||
const fechaFinEvento = new Date(fecha_fin2.fecha_fin); // UTC
|
const fechaFinEvento = new Date(fecha_fin2.fecha_fin); // UTC
|
||||||
const now = new Date();
|
const now = new Date();
|
||||||
console.log(fechaFinEvento.getTime())
|
console.log("Fecha fin cruda (de DB):", fecha_fin2.fecha_fin);
|
||||||
console.log(now.getTime)
|
console.log("Fecha fin convertida:", fechaFinEvento.toISOString());
|
||||||
|
console.log("Fecha fin timestamp:", fechaFinEvento.getTime());
|
||||||
|
console.log("Fecha actual:", now.toISOString());
|
||||||
|
console.log("Fecha actual timestamp:", now.getTime());
|
||||||
if (fechaFinEvento.getTime() < now.getTime()) {
|
if (fechaFinEvento.getTime() < now.getTime()) {
|
||||||
throw new Error('El evento ha finalizado');
|
throw new Error('El evento ha finalizado');
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user