Se generalizó envio de correos a diferentes sistemas
This commit is contained in:
@@ -0,0 +1,22 @@
|
||||
// auth.module.ts
|
||||
import { Module } from '@nestjs/common';
|
||||
import { JwtModule } from '@nestjs/jwt';
|
||||
import { ConfigModule, ConfigService } from '@nestjs/config';
|
||||
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' },
|
||||
}),
|
||||
}),
|
||||
],
|
||||
providers: [AuthService],
|
||||
exports: [AuthService, JwtModule],
|
||||
})
|
||||
export class AuthModule {}
|
||||
@@ -0,0 +1,24 @@
|
||||
import { Injectable } from '@nestjs/common';
|
||||
import { JwtService } from '@nestjs/jwt';
|
||||
|
||||
@Injectable()
|
||||
export class AuthService {
|
||||
constructor(private jwtService: JwtService) {}
|
||||
|
||||
generarToken(payload: any) {
|
||||
return this.jwtService.sign(payload, {
|
||||
secret: process.env.JWT_SECRET, // <-- Aquí lo defines explícitamente
|
||||
expiresIn: '1d',
|
||||
});
|
||||
}
|
||||
|
||||
verificarToken(token: string) {
|
||||
try {
|
||||
return this.jwtService.verify(token, {
|
||||
secret: process.env.JWT_SECRET, // <-- También aquí
|
||||
});
|
||||
} catch {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user