2024-01-25 16:17:13 +00:00
|
|
|
import {
|
2024-02-03 14:41:32 +00:00
|
|
|
Body,
|
|
|
|
Controller,
|
|
|
|
HttpCode,
|
|
|
|
Post,
|
|
|
|
Request,
|
|
|
|
UseGuards,
|
2024-01-25 16:17:13 +00:00
|
|
|
} from "@nestjs/common";
|
|
|
|
import {
|
2024-02-03 14:41:32 +00:00
|
|
|
ApiOkResponse,
|
|
|
|
ApiOperation,
|
|
|
|
ApiTags,
|
|
|
|
ApiUnauthorizedResponse,
|
2024-01-25 16:17:13 +00:00
|
|
|
} from "@nestjs/swagger";
|
2024-02-05 18:08:32 +00:00
|
|
|
import { Public } from "src/decorators/public.decorator";
|
2024-01-25 16:17:13 +00:00
|
|
|
import { AuthService } from "./auth.service";
|
|
|
|
import { LoginUserDTO } from "./dto/login.dto";
|
2024-02-03 14:41:32 +00:00
|
|
|
import { LocalAuthGuard } from "./local-auth.guard";
|
2024-01-25 16:17:13 +00:00
|
|
|
|
|
|
|
@ApiTags("Auth")
|
|
|
|
@Controller("auth")
|
|
|
|
export class AuthController {
|
2024-02-03 14:41:32 +00:00
|
|
|
constructor(private authService: AuthService) {}
|
2024-01-25 16:17:13 +00:00
|
|
|
|
2024-02-03 14:41:32 +00:00
|
|
|
@Public()
|
|
|
|
@UseGuards(LocalAuthGuard)
|
|
|
|
@Post("/")
|
|
|
|
@ApiOperation({ summary: "Authenticates a user" })
|
|
|
|
@ApiOkResponse({ status: 200, description: "Authenticated successfully" })
|
|
|
|
@ApiUnauthorizedResponse({ description: "Wrong username or password" })
|
|
|
|
@HttpCode(200)
|
|
|
|
async login(@Request() req, @Body() _: LoginUserDTO) {
|
|
|
|
return this.authService.login(req.user);
|
|
|
|
}
|
2024-01-25 16:17:13 +00:00
|
|
|
}
|