mirror of
https://github.com/SyncrowIOT/backend.git
synced 2025-11-26 16:14:55 +00:00
Merge pull request #77 from SyncrowIOT/SP-342-implement-region-end-point-in-the-login
error handling for login
This commit is contained in:
@ -90,39 +90,43 @@ export class UserAuthService {
|
||||
}
|
||||
|
||||
async userLogin(data: UserLoginDto) {
|
||||
const user = await this.authService.validateUser(
|
||||
data.email,
|
||||
data.password,
|
||||
data.regionUuid,
|
||||
);
|
||||
try {
|
||||
const user = await this.authService.validateUser(
|
||||
data.email,
|
||||
data.password,
|
||||
data.regionUuid,
|
||||
);
|
||||
|
||||
if (!user) {
|
||||
throw new UnauthorizedException('Invalid login credentials.');
|
||||
}
|
||||
if (!user) {
|
||||
throw new UnauthorizedException('Invalid login credentials.');
|
||||
}
|
||||
|
||||
const session = await Promise.all([
|
||||
await this.sessionRepository.update(
|
||||
{ userId: user.id },
|
||||
{
|
||||
isLoggedOut: true,
|
||||
},
|
||||
),
|
||||
await this.authService.createSession({
|
||||
const session = await Promise.all([
|
||||
await this.sessionRepository.update(
|
||||
{ userId: user.id },
|
||||
{
|
||||
isLoggedOut: true,
|
||||
},
|
||||
),
|
||||
await this.authService.createSession({
|
||||
userId: user.uuid,
|
||||
loginTime: new Date(),
|
||||
isLoggedOut: false,
|
||||
}),
|
||||
]);
|
||||
|
||||
return await this.authService.login({
|
||||
email: user.email,
|
||||
userId: user.uuid,
|
||||
loginTime: new Date(),
|
||||
isLoggedOut: false,
|
||||
}),
|
||||
]);
|
||||
|
||||
return await this.authService.login({
|
||||
email: user.email,
|
||||
userId: user.uuid,
|
||||
uuid: user.uuid,
|
||||
roles: user?.roles?.map((role) => {
|
||||
return { uuid: role.uuid, type: role.roleType.type };
|
||||
}),
|
||||
sessionId: session[1].uuid,
|
||||
});
|
||||
uuid: user.uuid,
|
||||
roles: user?.roles?.map((role) => {
|
||||
return { uuid: role.uuid, type: role.roleType.type };
|
||||
}),
|
||||
sessionId: session[1].uuid,
|
||||
});
|
||||
} catch (error) {
|
||||
throw new BadRequestException('Wrong email, password or region');
|
||||
}
|
||||
}
|
||||
|
||||
async deleteUser(uuid: string) {
|
||||
|
||||
Reference in New Issue
Block a user