Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 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 33 34 | 2x 2x 2x 2x 2x 2x 2x 1x 2x 1x | import { Body, Controller, HttpCode, Post } from '@nestjs/common';
import {
ApiOkResponse,
ApiOperation,
ApiTags,
ApiUnauthorizedResponse,
} from '@nestjs/swagger';
import { Public, UserRole } from './auth.decorators';
import { AuthService } from './auth.service';
import { LoginDto } from './dto/login.dto';
import { LoginResponse } from './dto/login-response.dto';
@ApiTags('auth')
@Controller('auth')
export class AuthController {
constructor(private readonly auth: AuthService) {}
@ApiOperation({
summary: 'Exchange credentials for a JWT',
description:
'Public. The returned accessToken (1h expiry) goes on every other request as "Authorization: Bearer <token>".',
})
@ApiOkResponse({ type: LoginResponse })
@ApiUnauthorizedResponse({ description: 'Invalid credentials' })
@Public()
@Post('login')
@HttpCode(200)
login(
@Body() dto: LoginDto,
): Promise<{ accessToken: string; role: UserRole }> {
return this.auth.login(dto.email, dto.password);
}
}
|