mirror of
https://github.com/SyncrowIOT/backend.git
synced 2025-11-26 08:04:53 +00:00
error handling for login
This commit is contained in:
@ -88,39 +88,43 @@ export class UserAuthService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async userLogin(data: UserLoginDto) {
|
async userLogin(data: UserLoginDto) {
|
||||||
const user = await this.authService.validateUser(
|
try {
|
||||||
data.email,
|
const user = await this.authService.validateUser(
|
||||||
data.password,
|
data.email,
|
||||||
data.regionUuid,
|
data.password,
|
||||||
);
|
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 },
|
||||||
{
|
{
|
||||||
isLoggedOut: true,
|
isLoggedOut: true,
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
await this.authService.createSession({
|
await this.authService.createSession({
|
||||||
|
userId: user.uuid,
|
||||||
|
loginTime: new Date(),
|
||||||
|
isLoggedOut: false,
|
||||||
|
}),
|
||||||
|
]);
|
||||||
|
|
||||||
|
return await this.authService.login({
|
||||||
|
email: user.email,
|
||||||
userId: user.uuid,
|
userId: user.uuid,
|
||||||
loginTime: new Date(),
|
uuid: user.uuid,
|
||||||
isLoggedOut: false,
|
roles: user?.roles?.map((role) => {
|
||||||
}),
|
return { uuid: role.uuid, type: role.roleType.type };
|
||||||
]);
|
}),
|
||||||
|
sessionId: session[1].uuid,
|
||||||
return await this.authService.login({
|
});
|
||||||
email: user.email,
|
} catch (error) {
|
||||||
userId: user.uuid,
|
throw new BadRequestException('Wrong email, password or region');
|
||||||
uuid: user.uuid,
|
}
|
||||||
roles: user?.roles?.map((role) => {
|
|
||||||
return { uuid: role.uuid, type: role.roleType.type };
|
|
||||||
}),
|
|
||||||
sessionId: session[1].uuid,
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
async deleteUser(uuid: string) {
|
async deleteUser(uuid: string) {
|
||||||
|
|||||||
Reference in New Issue
Block a user