mirror of
https://github.com/SyncrowIOT/backend.git
synced 2025-07-14 18:05:48 +00:00
Refactor and enhance user authentication in AuthService
This commit is contained in:
@ -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> {
|
||||
|
Reference in New Issue
Block a user