Skip to content
This repository was archived by the owner on Jan 28, 2026. It is now read-only.

Commit d7ac9d4

Browse files
committed
fix: Update login endpoint and error handling to clarify admin-only access and improve exception handling
1 parent fb51638 commit d7ac9d4

2 files changed

Lines changed: 6 additions & 4 deletions

File tree

src/auth/auth.controller.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,10 @@ export class AuthController {
1818
@Post('login')
1919
@UseInterceptors(LoginLoggingInterceptor)
2020
@ZodValidation(loginSchema)
21-
@ApiOperation({ summary: 'Вход пользователя' })
21+
@ApiOperation({ summary: 'Вход пользователя (только для администраторов)' })
2222
@ApiBody({ type: LoginDtoClass })
2323
@ApiResponse({ status: 200, description: 'Успешный вход', type: LoginDtoClass })
24-
@ApiResponse({ status: 401, description: 'Неверный email или пароль' })
24+
@ApiResponse({ status: 401, description: 'Неверный email или пароль, либо недостаточно прав' })
2525
login(@Body() loginDto: LoginDto) {
2626
return this.authService.login(loginDto);
2727
}

src/auth/auth.service.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ export class AuthService {
4848

4949
// Проверяем, что пользователь имеет роль ADMIN
5050
if (user.role !== 'ADMIN') {
51-
throw new BadRequestException('Доступ разрешен только администраторам');
51+
throw new UnauthorizedException('Доступ разрешен только администраторам');
5252
}
5353

5454
const payload = { email: user.email, sub: user.id };
@@ -72,6 +72,8 @@ export class AuthService {
7272
};
7373
} catch (error) {
7474
this.logger.error(error);
75+
// Пробрасываем ошибку дальше, чтобы она вернулась клиенту
76+
throw error;
7577
}
7678
}
7779

@@ -89,7 +91,7 @@ export class AuthService {
8991

9092
// Проверяем, что пользователь имеет роль ADMIN
9193
if (user.role !== 'ADMIN') {
92-
throw new BadRequestException('Доступ разрешен только администраторам');
94+
throw new UnauthorizedException('Доступ разрешен только администраторам');
9395
}
9496

9597
const newPayload = { email: user.email, sub: user.id };

0 commit comments

Comments
 (0)