feat: auth module
This commit is contained in:
@@ -0,0 +1,23 @@
|
||||
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);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user