feat: add otp and hashing modules
This commit is contained in:
@@ -1,6 +1,8 @@
|
||||
import { UsersService } from '@/modules/users/providers/users.service';
|
||||
import { Injectable, UnauthorizedException } from '@nestjs/common';
|
||||
import { LoginDTO } from '../dtos/login.dto';
|
||||
import { OtpService } from '@/modules/otp/providers/otp.service';
|
||||
import { HashingProvider } from '@/common/modules/hashing/providers/hashing.provider';
|
||||
|
||||
@Injectable()
|
||||
export class AuthService {
|
||||
@@ -9,6 +11,16 @@ export class AuthService {
|
||||
* Inject Users Service
|
||||
*/
|
||||
private readonly usersService: UsersService,
|
||||
|
||||
/**
|
||||
* Inject OTP Service
|
||||
*/
|
||||
private readonly otpService: OtpService,
|
||||
|
||||
/**
|
||||
* Inject Hashing Provider
|
||||
*/
|
||||
private readonly hashingProvider: HashingProvider,
|
||||
) {}
|
||||
|
||||
public async logIn(loginDto: LoginDTO) {
|
||||
@@ -17,10 +29,13 @@ export class AuthService {
|
||||
|
||||
if (!user) {
|
||||
// TODO: Send OTP
|
||||
const otpCode = await this.otpService.createOTP(phone);
|
||||
|
||||
return {
|
||||
newUser: true,
|
||||
message: `Otp sent to ${phone}`,
|
||||
// Just for development
|
||||
code: otpCode,
|
||||
};
|
||||
}
|
||||
|
||||
@@ -31,8 +46,12 @@ export class AuthService {
|
||||
};
|
||||
}
|
||||
|
||||
// TODO: Hash password and compare
|
||||
if (password === user.password) {
|
||||
const isPasswordCorrect = await this.hashingProvider.compare(
|
||||
password,
|
||||
user.password || '',
|
||||
);
|
||||
|
||||
if (isPasswordCorrect) {
|
||||
// TODO: Create JWT
|
||||
|
||||
return { access: 'ACCESS_TOKEN', refresh: 'REFRESH_TOKEN' };
|
||||
|
||||
Reference in New Issue
Block a user