tryed to remove bcrypt for bcryptjs

This commit is contained in:
Kevsl 2024-06-18 21:40:41 +02:00
parent 3d38030791
commit e114468157

View File

@ -1,7 +1,8 @@
import { ForbiddenException, Injectable } from '@nestjs/common'; import { ForbiddenException, Injectable } from '@nestjs/common';
import { PrismaService } from '../prisma/prisma.service'; import { PrismaService } from '../prisma/prisma.service';
import { AuthLoginDto, AuthRegisterDto } from './dto'; import { AuthLoginDto, AuthRegisterDto } from './dto';
import * as argon from 'argon2'; import bcrypt from 'bcryptjs';
import { Prisma, User } from '@prisma/client'; import { Prisma, User } from '@prisma/client';
import { JwtService } from '@nestjs/jwt'; import { JwtService } from '@nestjs/jwt';
import { ConfigService } from '@nestjs/config'; import { ConfigService } from '@nestjs/config';
@ -15,7 +16,7 @@ export class AuthService {
) {} ) {}
async signup(dto: AuthRegisterDto) { async signup(dto: AuthRegisterDto) {
const hash = await argon.hash(dto.password); const hash = await bcrypt.hashSync(dto.password);
const promoCode = await this.prisma.promoCode.findFirst({ const promoCode = await this.prisma.promoCode.findFirst({
where: { where: {
name: dto.promoCode, name: dto.promoCode,
@ -73,7 +74,8 @@ export class AuthService {
}); });
if (!userDatas) throw new ForbiddenException('Credentials incorrect'); if (!userDatas) throw new ForbiddenException('Credentials incorrect');
const pwMatches = await argon.verify(userDatas.hash, dto.password); const pwMatches = await bcrypt.compareSync(userDatas.hash, dto.password);
if (!pwMatches) throw new ForbiddenException('Credentials incorrect'); if (!pwMatches) throw new ForbiddenException('Credentials incorrect');
return this.signToken(userDatas); return this.signToken(userDatas);