feat: add simple login logic
This commit is contained in:
@@ -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.',
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user