24 lines
928 B
TypeScript
24 lines
928 B
TypeScript
import { BadRequestException, Injectable } from "@nestjs/common";
|
|
import { UsersService } from "../users/providers/users.service";
|
|
import { LoginPasswordDTO } from "./DTOs/loginPassword.dto";
|
|
import { PasswordService } from "../utils/providers/password.service";
|
|
import { AuthMessage, UserMessage } from "../../common/enums/message.enum";
|
|
|
|
@Injectable()
|
|
export class AuthService {
|
|
constructor(
|
|
private readonly userSerivce: UsersService,
|
|
private readonly passwordService: PasswordService,
|
|
) {}
|
|
|
|
async loginWithPassword(loginDto: LoginPasswordDTO) {
|
|
const { email, password } = loginDto;
|
|
|
|
const user = await this.userSerivce.findOneWithEmail(email);
|
|
if (!user) throw new BadRequestException(UserMessage.USER_NOT_FOUND);
|
|
|
|
const passCompare = await this.passwordService.comparePassword(password, user.password);
|
|
if (!passCompare) throw new BadRequestException(AuthMessage.INVALID_PASSWORD);
|
|
}
|
|
}
|