17 lines
580 B
TypeScript
17 lines
580 B
TypeScript
import { Controller, Post, Body, UnauthorizedException } from '@nestjs/common';
|
|
import { AuthService } from './auth.service';
|
|
|
|
@Controller('auth')
|
|
export class AuthController {
|
|
constructor(private authService: AuthService) { }
|
|
|
|
@Post('login')
|
|
async login(@Body() body: { login: string; password: string }) {
|
|
const user = await this.authService.validateUser(body.login, body.password);
|
|
if (!user) {
|
|
throw new UnauthorizedException('Неверный логин или пароль');
|
|
}
|
|
return { success: true, user };
|
|
}
|
|
}
|