Skip to content

Commit

Permalink
Chore: Set swagger authorization header
Browse files Browse the repository at this point in the history
- 스웨거에서 인증 헤더 설정할 수 있도록 옵션 추가
  • Loading branch information
sally0226 committed Jul 4, 2024
1 parent c68ec16 commit 5264636
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 2 deletions.
2 changes: 2 additions & 0 deletions src/app.controller.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { Controller, Get, InternalServerErrorException } from '@nestjs/common';
import { ApiBearerAuth } from '@nestjs/swagger';

import { AppService } from './app.service';
import { UseAuthGuard } from './common/decorators/auth-guard.decorator';
Expand All @@ -18,6 +19,7 @@ export class AppController {

@Get('/me')
@UseAuthGuard([UserRole.USER])
@ApiBearerAuth()
getMe(@CurrentUser() user: User): User {
return user;
}
Expand Down
1 change: 1 addition & 0 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ async function bootstrap() {
const config = new DocumentBuilder()
.setTitle('Korrk API')
.setDescription('Mashup의 VitaminC팀 API 서버입니다')
.addBearerAuth()
.build();

const document = SwaggerModule.createDocument(app, config);
Expand Down
10 changes: 9 additions & 1 deletion src/map/map.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,12 @@ import {
Patch,
Post,
} from '@nestjs/common';
import { ApiOkResponse, ApiOperation, ApiTags } from '@nestjs/swagger';
import {
ApiBearerAuth,
ApiOkResponse,
ApiOperation,
ApiTags,
} from '@nestjs/swagger';

import { UseAuthGuard } from '../common/decorators/auth-guard.decorator';
import { CurrentUser } from '../common/decorators/user.decorator';
Expand Down Expand Up @@ -49,19 +54,22 @@ export class MapController {

@Get(':id')
@ApiOkResponse({ type: MapResponseDto })
@ApiBearerAuth()
findOne(@Param('id') id: string) {
// TODO: findOne For user로 만들어서 (ADMIN, READ, WRITE)권한없으면 403을 반환하는 라우트를 만들어야 합니다.
return this.mapService.findOne({ id });
}

@Patch(':id')
@ApiOkResponse({ type: MapResponseDto })
@ApiBearerAuth()
update(@Param('id') id: string, @Body() updateMapDto: UpdateMapDto) {
return this.mapService.update(id, updateMapDto);
}

@Delete(':id')
@ApiOkResponse({ type: Number })
@ApiBearerAuth()
remove(@Param('id') id: string) {
return this.mapService.remove(id);
}
Expand Down
5 changes: 4 additions & 1 deletion src/user/user.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import {
Patch,
Query,
} from '@nestjs/common';
import { ApiOkResponse, ApiTags } from '@nestjs/swagger';
import { ApiBearerAuth, ApiOkResponse, ApiTags } from '@nestjs/swagger';

import { UseAuthGuard } from 'src/common/decorators/auth-guard.decorator';
import { CurrentUser } from 'src/common/decorators/user.decorator';
Expand All @@ -25,6 +25,7 @@ export class UserController {
@Get(':id')
@UseAuthGuard([UserRole.USER])
@ApiOkResponse({ type: UserResponseDto })
@ApiBearerAuth()
async findOne(@Param('id') id: string) {
const user = await this.userService.findOne({ id: +id });
return user;
Expand All @@ -33,6 +34,7 @@ export class UserController {
@Patch()
@UseAuthGuard([UserRole.USER])
@ApiOkResponse({ type: UserResponseDto })
@ApiBearerAuth()
async update(
@Body() updateUserDto: UpdateUserRequestDto,
@CurrentUser() user: User,
Expand All @@ -42,6 +44,7 @@ export class UserController {

@Delete(':id')
@ApiOkResponse({ type: Number })
@ApiBearerAuth()
async remove(@Param('id') id: string) {
return this.userService.remove(+id);
}
Expand Down

0 comments on commit 5264636

Please sign in to comment.