-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathapp.controller.ts
More file actions
32 lines (30 loc) · 1.06 KB
/
Copy pathapp.controller.ts
File metadata and controls
32 lines (30 loc) · 1.06 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
import { Body, Controller, Post, UseGuards } from '@nestjs/common';
import {
ApiCreatedResponse,
ApiOperation,
ApiUnauthorizedResponse,
} from '@nestjs/swagger';
import { AuthService } from './auth/auth.service';
import { AuthUserDTO } from './auth/dto/auth-user.dto';
import { LoggedInTokenResponse } from './auth/dto/logged-in-token-response.dto';
import { UnauthorizedResponse } from './auth/dto/unothorized-response.dto';
import { LocalAuthGuard } from './auth/local-auth.guard';
import { User } from './users/user.entity';
@Controller()
export class AppController {
constructor(private readonly authService: AuthService) {}
@ApiOperation({ summary: 'Authenticate and get token' })
@ApiCreatedResponse({
type: LoggedInTokenResponse,
description: 'JWT token',
})
@ApiUnauthorizedResponse({
type: UnauthorizedResponse,
description: 'Invalid username or password',
})
@UseGuards(LocalAuthGuard)
@Post('auth/login')
login(@Body() authUserDTO: AuthUserDTO): { access_token: string } {
return this.authService.login(new User(authUserDTO));
}
}