project-knedita/src/auth/auth.controller.ts

36 lines
881 B
TypeScript
Raw Normal View History

import {
2024-02-03 14:41:32 +00:00
Body,
Controller,
HttpCode,
Post,
Request,
UseGuards,
} from "@nestjs/common";
import {
2024-02-03 14:41:32 +00:00
ApiOkResponse,
ApiOperation,
ApiTags,
ApiUnauthorizedResponse,
} from "@nestjs/swagger";
2024-02-03 14:41:32 +00:00
import { Public } from "src/public.decorator";
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";
@ApiTags("Auth")
@Controller("auth")
export class AuthController {
2024-02-03 14:41:32 +00:00
constructor(private authService: AuthService) {}
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);
}
}