se agregó expiración
This commit is contained in:
@@ -50,7 +50,7 @@ export class QrTokenService {
|
||||
console.log("fecha de caducidad:",fecha_fin);
|
||||
// Convert fecha_fin to seconds from now for expiresIn
|
||||
const expiresInSeconds = Math.floor((fecha_fin.getTime() - Date.now()) / 1000);
|
||||
|
||||
console.log("expiresInSeconds:",expiresInSeconds);
|
||||
return this.jwtService.sign(payload, {
|
||||
secret,
|
||||
expiresIn: expiresInSeconds > 0 ? expiresInSeconds : 0, // El QR puede ser válido por 30 días
|
||||
@@ -69,6 +69,7 @@ export class QrTokenService {
|
||||
id_cuestionario: number;
|
||||
type: string;
|
||||
iat: number;
|
||||
exp?: number;
|
||||
} | null >{
|
||||
try {
|
||||
const secret =
|
||||
@@ -83,17 +84,20 @@ export class QrTokenService {
|
||||
where: { id_evento:decoded.id_evento },
|
||||
|
||||
});
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
if (!fecha_fin2) {
|
||||
throw new UnauthorizedException('Evento no encontrado');
|
||||
}
|
||||
|
||||
fecha_fin2
|
||||
|
||||
const fechaFinEvento = new Date(fecha_fin2.fecha_fin); // UTC
|
||||
const now = new Date();
|
||||
console.log(fechaFinEvento.getTime())
|
||||
console.log(now.getTime)
|
||||
console.log(fechaFinEvento)
|
||||
console.log(now.getTime())
|
||||
if (fechaFinEvento.getTime() < now.getTime()) {
|
||||
throw new Error('El evento ha finalizado');
|
||||
}
|
||||
@@ -109,6 +113,7 @@ export class QrTokenService {
|
||||
id_cuestionario: decoded.id_cuestionario,
|
||||
type: decoded.type,
|
||||
iat: decoded.iat,
|
||||
exp: decoded.exp,
|
||||
};
|
||||
} catch (error) {
|
||||
console.error('Error validando token QR:', error.message);
|
||||
|
||||
Reference in New Issue
Block a user