Refactor and enhance user authentication in AuthService

This commit is contained in:
faris Aljohari
2025-01-08 00:14:21 -06:00
parent 38b6cd1a62
commit a8ac2ecae3

View File

@ -33,32 +33,33 @@ export class AuthService {
const user = await this.userRepository.findOne({
where: {
email,
region: regionUuid
? {
uuid: regionUuid,
}
: undefined,
region: regionUuid ? { uuid: regionUuid } : undefined,
},
relations: ['roleType'],
});
if (!user) {
throw new BadRequestException('Invalid credentials');
}
if (!user.isUserVerified) {
throw new BadRequestException('User is not verified');
}
if (!user.isActive) {
throw new BadRequestException('User is not active');
}
if (user) {
const passwordMatch = this.helperHashService.bcryptCompare(
pass,
user.password,
);
if (passwordMatch) {
const { ...result } = user;
return result;
}
const passwordMatch = await this.helperHashService.bcryptCompare(
pass,
user.password,
);
if (!passwordMatch) {
throw new BadRequestException('Invalid credentials');
}
return null;
// eslint-disable-next-line @typescript-eslint/no-unused-vars
const { password, ...result } = user;
return result;
}
async createSession(data): Promise<UserSessionEntity> {