mirror of
https://github.com/SyncrowIOT/backend.git
synced 2025-07-16 18:56:22 +00:00
error handling for login
This commit is contained in:
@ -40,7 +40,7 @@ export class UserAuthService {
|
|||||||
throw new BadRequestException('User already registered with given email');
|
throw new BadRequestException('User already registered with given email');
|
||||||
}
|
}
|
||||||
const salt = this.helperHashService.randomSalt(10); // Hash the password using bcrypt
|
const salt = this.helperHashService.randomSalt(10); // Hash the password using bcrypt
|
||||||
const hashedPassword = await this.helperHashService.bcrypt(
|
const hashedPassword = this.helperHashService.bcrypt(
|
||||||
userSignUpDto.password,
|
userSignUpDto.password,
|
||||||
salt,
|
salt,
|
||||||
);
|
);
|
||||||
@ -90,16 +90,15 @@ export class UserAuthService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async userLogin(data: UserLoginDto) {
|
async userLogin(data: UserLoginDto) {
|
||||||
|
try {
|
||||||
const user = await this.authService.validateUser(
|
const user = await this.authService.validateUser(
|
||||||
data.email,
|
data.email,
|
||||||
data.password,
|
data.password,
|
||||||
data.regionUuid,
|
data.regionUuid,
|
||||||
);
|
);
|
||||||
|
|
||||||
if (!user) {
|
if (!user) {
|
||||||
throw new UnauthorizedException('Invalid login credentials.');
|
throw new UnauthorizedException('Invalid login credentials.');
|
||||||
}
|
}
|
||||||
|
|
||||||
const session = await Promise.all([
|
const session = await Promise.all([
|
||||||
await this.sessionRepository.update(
|
await this.sessionRepository.update(
|
||||||
{ userId: user.id },
|
{ userId: user.id },
|
||||||
@ -113,7 +112,6 @@ export class UserAuthService {
|
|||||||
isLoggedOut: false,
|
isLoggedOut: false,
|
||||||
}),
|
}),
|
||||||
]);
|
]);
|
||||||
|
|
||||||
return await this.authService.login({
|
return await this.authService.login({
|
||||||
email: user.email,
|
email: user.email,
|
||||||
userId: user.uuid,
|
userId: user.uuid,
|
||||||
@ -123,6 +121,9 @@ export class UserAuthService {
|
|||||||
}),
|
}),
|
||||||
sessionId: session[1].uuid,
|
sessionId: session[1].uuid,
|
||||||
});
|
});
|
||||||
|
} catch (error) {
|
||||||
|
throw new UnauthorizedException('User unauthorized');
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async deleteUser(uuid: string) {
|
async deleteUser(uuid: string) {
|
||||||
|
Reference in New Issue
Block a user