feat: add otp and hashing modules

This commit is contained in:
2026-02-21 09:10:45 +03:30
parent e657264807
commit 20c89c472c
12 changed files with 1122 additions and 1298 deletions
+21 -2
View File
@@ -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' };