1
0

fix api doc for auth endpoints

This commit is contained in:
wodka 2019-07-30 13:03:20 +02:00
parent 7c30574bf2
commit fdcc9fda3f
4 changed files with 24 additions and 9 deletions

View File

@ -1,20 +1,30 @@
import { Controller, Request, Post, UseGuards } from '@nestjs/common';
import { AuthGuard } from '@nestjs/passport';
import { AuthService } from "../services/auth.service"
import { AuthJwtDto } from "../dto/auth.jwt.dto"
import {ApiBearerAuth, ApiImplicitBody, ApiImplicitQuery, ApiResponse, ApiUseTags} from "@nestjs/swagger"
@ApiUseTags('authentication')
@Controller('auth')
export class AuthController {
constructor(private readonly authService: AuthService) {}
@ApiResponse({ status: 201, description: 'Successful login.', type: AuthJwtDto})
@ApiResponse({ status: 401, description: 'Invalid Credentials.'})
@ApiImplicitQuery({name: 'username', type: String})
@ApiImplicitQuery({name: 'password', type: String})
@UseGuards(AuthGuard('password'))
@Post('login')
async login(@Request() req) {
async login(@Request() req): Promise<AuthJwtDto> {
return this.authService.createToken(req.user);
}
@ApiBearerAuth()
@ApiResponse({ status: 201, description: 'Consumed Refresh Token.', type: AuthJwtDto})
@ApiResponse({ status: 401, description: 'Invalid Token.'})
@UseGuards(AuthGuard('jwt.refresh'))
@Post('refresh')
async refresh(@Request() req) {
async refresh(@Request() req): Promise<AuthJwtDto> {
return this.authService.createToken(req.user);
}
}

View File

@ -0,0 +1,9 @@
import { ApiModelProperty } from '@nestjs/swagger';
export class AuthJwtDto {
@ApiModelProperty()
access_token: string;
@ApiModelProperty()
refresh_token: string;
}

View File

@ -1,4 +0,0 @@
export interface AuthJwt {
access_token: string;
refresh_token: string;
}

View File

@ -4,7 +4,7 @@ import { PasswordService } from "./password.service"
import { JwtService } from '@nestjs/jwt';
import { AuthUser } from "../interfaces/auth.user.interface"
import { User } from "../../users/interfaces/user.interface"
import {AuthJwt} from "../interfaces/auth.jwt.interface"
import {AuthJwtDto} from "../dto/auth.jwt.dto"
@Injectable()
export class AuthService {
@ -47,7 +47,7 @@ export class AuthService {
};
}
async createToken(user: AuthUser): Promise<AuthJwt> {
async createToken(user: AuthUser): Promise<AuthJwtDto> {
const payload = {
id: user.id,
username: user.username,