From 6fc315450d9473506bdbaa1640657ed31a8d3bc0 Mon Sep 17 00:00:00 2001 From: jorge miguel Date: Tue, 9 Sep 2025 17:43:23 -0600 Subject: [PATCH] feat: add token validation endpoint and logic for QR token verification --- .../participante_evento.controller.ts | 6 ++++++ .../participante_evento.service.ts | 14 ++++++++++++++ src/qr/qr-token.service.ts | 2 ++ 3 files changed, 22 insertions(+) diff --git a/src/participante_evento/participante_evento.controller.ts b/src/participante_evento/participante_evento.controller.ts index df24753..bc450cb 100644 --- a/src/participante_evento/participante_evento.controller.ts +++ b/src/participante_evento/participante_evento.controller.ts @@ -233,6 +233,12 @@ export class ParticipanteEventoController { ); } + @Post('decode-token') + decodeToken(@Body() body: { token: string }) { + return this.participanteEventoService.validToken( + body.token, + ); + } @ApiOperation({ summary: 'Registrar asistencia usando token QR', }) diff --git a/src/participante_evento/participante_evento.service.ts b/src/participante_evento/participante_evento.service.ts index 205fce9..cbb2dab 100644 --- a/src/participante_evento/participante_evento.service.ts +++ b/src/participante_evento/participante_evento.service.ts @@ -260,4 +260,18 @@ export class ParticipanteEventoService { }, }; } + + async validToken(qrToken: string) { + // Validar el token QR + const tokenData = this.qrTokenService.validateQrToken(qrToken); + + if (!tokenData) { + throw new HttpException( + 'Token QR inválido o expirado', + HttpStatus.BAD_REQUEST, + ); + } + + return tokenData + } } diff --git a/src/qr/qr-token.service.ts b/src/qr/qr-token.service.ts index f0792e1..e5243c4 100644 --- a/src/qr/qr-token.service.ts +++ b/src/qr/qr-token.service.ts @@ -57,6 +57,8 @@ export class QrTokenService { this.configService.get('QR_JWT_SECRET') || this.configService.get('JWT_SECRET', 'tu_clave_secreta'); + console.log(secret) + const decoded = this.jwtService.verify(token, { secret }); // Verificar que sea un token de tipo QR de asistencia