feat: add simple login logic

This commit is contained in:
2026-02-18 09:13:23 +03:30
parent b9779f7cb6
commit e657264807
16 changed files with 259 additions and 13 deletions
@@ -0,0 +1,45 @@
import { UsersService } from '@/modules/users/providers/users.service';
import { Injectable, UnauthorizedException } from '@nestjs/common';
import { LoginDTO } from '../dtos/login.dto';
@Injectable()
export class AuthService {
constructor(
/**
* Inject Users Service
*/
private readonly usersService: UsersService,
) {}
public async logIn(loginDto: LoginDTO) {
const { phone, password } = loginDto;
const user = await this.usersService.findOneByPhone(phone);
if (!user) {
// TODO: Send OTP
return {
newUser: true,
message: `Otp sent to ${phone}`,
};
}
if (!password) {
return {
newUser: false,
message: 'Please send password',
};
}
// TODO: Hash password and compare
if (password === user.password) {
// TODO: Create JWT
return { access: 'ACCESS_TOKEN', refresh: 'REFRESH_TOKEN' };
}
throw new UnauthorizedException(
'Entered phone number or password is wrong.',
);
}
}