Se agregaron funciones y cambios en los dto

This commit is contained in:
2025-10-16 14:04:30 -06:00
parent cdf3b761e4
commit 09fda8af12
16 changed files with 1470 additions and 296 deletions
+6 -5
View File
@@ -14,6 +14,7 @@ import { gmail } from 'src/helpers.services/gmail.service';
import { Servicio } from 'src/servicio/entities/servicio.entity';
import { Usuario } from 'src/usuario/entities/usuario.entity';
import { Like, Not, Repository } from 'typeorm';
import * as argon2 from 'argon2';
@Injectable()
export class AuthService {
@@ -80,15 +81,15 @@ export class AuthService {
}
async comparar(password, dbPassword) {
if (!bcrypt.compareSync(password, dbPassword)) {
return false;
} else {
if (await argon2.verify(password, dbPassword)) {
return true;
} else {
return false;
}
}
async encriptar(password) {
return bcrypt.hashSync(password, Number(process.env.SALT_ROUNDS));
return await argon2.hash(password);
}
async generarPassword() {
@@ -107,7 +108,7 @@ export class AuthService {
async login(usuario: string, password: string) {
const user = await this.userRepo.findOne({ where: { usuario } });
if (!user) throw new UnauthorizedException('No existe este usuario.');
const match = await bcrypt.compare(password, user.password);
const match = await this.comparar(password, user.password);
if (!match) throw new UnauthorizedException('Credenciales inválidas');
if (!user.activo) throw new Error('Este usuario no esta activo.');
const token = this.jwtCreate(