se hizo el service cuestionario-alumno

This commit is contained in:
evenegas
2025-05-20 15:53:57 -06:00
parent 27e73d9514
commit b786976565
79 changed files with 3318 additions and 169 deletions
+15
View File
@@ -0,0 +1,15 @@
import { JwtModule } from '@nestjs/jwt';
import { Module } from '@nestjs/common';
import { AuthService } from './auth.service';
@Module({
imports: [
JwtModule.register({
secret: 'secretoSuperSeguro', // Usa un .env en producción
signOptions: { expiresIn: '1h' },
}),
],
providers: [AuthService],
exports: [AuthService],
})
export class AuthModule {}
+31
View File
@@ -0,0 +1,31 @@
import { Injectable, UnauthorizedException } from '@nestjs/common';
import { JwtService } from '@nestjs/jwt';
@Injectable()
export class AuthService {
constructor(private readonly jwtService: JwtService) {}
async jwtVerificar(token:string){
try{
const payload= this.jwtService.verify(token)
return payload;
}catch(err){
if (err.name === 'TokenExpiredError') {
throw new UnauthorizedException('El token ha expirado');
} else if (err.name === 'JsonWebTokenError') {
throw new UnauthorizedException('Token inválido');
} else {
throw new UnauthorizedException('Error al verificar el token');
}
}
}
async jwtCreate(idUsuario: number, idTipoUsuario:number) {
const payload = { Usuario:idUsuario , tipoUsuario: idTipoUsuario };
return {
access_token: this.jwtService.sign(payload),
};
}
}