Skip to content

Commit

Permalink
feat: adicionado security ao swagger
Browse files Browse the repository at this point in the history
  • Loading branch information
erikfig committed Sep 19, 2024
1 parent 5ad295d commit 069076f
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ async function bootstrap() {
.setDescription('Login Service')
.setVersion('1.0')
.addTag('login')
.addBearerAuth()
.build();

const document = SwaggerModule.createDocument(app, config);
Expand Down
8 changes: 8 additions & 0 deletions src/users/auth/auth.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,22 +9,30 @@ import {
import { AuthService } from './auth.service';
import { AuthGuard } from './auth.guard';
import { AuthRequestDto } from './auth-request.dto';
import { ApiBearerAuth, ApiResponse } from '@nestjs/swagger';

@Controller('auth')
export class AuthController {
constructor(private service: AuthService) {}

@ApiBearerAuth()
@ApiResponse({ status: 200, description: 'Success.' })
@ApiResponse({ status: 403, description: 'Forbidden.' })
@UseGuards(AuthGuard)
@Get('me')
public me(@Request() req) {
return this.service.me(req.user);
}

@ApiResponse({ status: 200, description: 'Success.' })
@Post('login')
public login(@Body() data: AuthRequestDto) {
return this.service.login(data);
}

@ApiBearerAuth()
@ApiResponse({ status: 200, description: 'Success.' })
@ApiResponse({ status: 403, description: 'Forbidden.' })
@UseGuards(AuthGuard)
@Post('logout')
public logout(@Request() req) {
Expand Down
7 changes: 7 additions & 0 deletions src/users/user/user.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,24 @@ import { UserCreateRequestDto } from './user-create-request.dto';
import { UserUpdateRequestDto } from './user-update-request.dto';
import { UserService } from './user.service';
import { AuthGuard } from '../auth/auth.guard';
import { ApiBearerAuth, ApiResponse } from '@nestjs/swagger';

@Controller('user')
export class UserController {
constructor(private service: UserService) {}

@ApiBearerAuth()
@ApiResponse({ status: 200, description: 'Success.' })
@ApiResponse({ status: 403, description: 'Forbidden.' })
@UseGuards(AuthGuard)
@Post()
public create(@Body() data: UserCreateRequestDto) {
return this.service.create(data);
}

@ApiBearerAuth()
@ApiResponse({ status: 200, description: 'Success.' })
@ApiResponse({ status: 403, description: 'Forbidden.' })
@UseGuards(AuthGuard)
@Patch(':id')
public update(@Param('id') id, @Body() data: UserUpdateRequestDto) {
Expand Down

0 comments on commit 069076f

Please sign in to comment.