ultima versión

This commit is contained in:
evenegas
2025-06-27 21:49:50 -06:00
parent ccf476bd6e
commit 904db0549f
4 changed files with 49 additions and 31 deletions
+6 -9
View File
@@ -7,16 +7,13 @@ import { AuthService } from './auth.service';
@Module({
imports: [
ConfigModule, // Ya es global, pero lo puedes dejar
JwtModule.registerAsync({
imports: [ConfigModule],
inject: [ConfigService],
useFactory: (config: ConfigService) => ({
secret: config.get('JWT_SECRET'),
signOptions: { expiresIn: '1d' },
}),
}),
JwtModule.register({
secret: process.env.JWT_SECRET
})
],
providers: [AuthService],
exports: [AuthService, JwtModule],
})
export class AuthModule {}
export class AuthModule { }
+18 -5
View File
@@ -6,20 +6,33 @@ export class AuthService {
constructor(private jwtService: JwtService) { }
generarToken(payload: any) {
console.log('JWT_SECRET:', process.env.JWT_SECRET);
return this.jwtService.sign(payload, {
secret: process.env.JWT_SECRET,
expiresIn: '1d',
});
}
verificarToken(token: string) {
async verificarToken(token: string) {
console.log('JWT_SECRET:', process.env.JWT_SECRET);
console.log('JWT_SECRET:', process.env.JWT_SECRET);
console.log('Verificando token:', token);
try {
return this.jwtService.verify(token, {
const result = await this.jwtService.verify(token, {
secret: process.env.JWT_SECRET,
});
} catch {
return null;
console.log('Resultado de verificación:', result);
return result;
} catch (error) {
throw new Error('Token inválido o expirado');
}
}
}