Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Public 데코레이터 추가 및 GetUser데코레이터 Failover처리 수정 #32

Merged
merged 4 commits into from
Jul 20, 2024

Conversation

J-Hoplin
Copy link
Collaborator

@J-Hoplin J-Hoplin commented Jul 1, 2024

PR 내용

추가 및 변경 사항

  • @Public()데코레이터 추가
    • 용도: Controller레벨 혹은 애플리케이션 레벨에서 Guard를 걸어둔 상태에서 특정 Route를 Public(인증 없어도 호출 가능)을 허용하거나 테스트용으로 활용하기 위해서 추가
    • 사용예시
@FolderControllerDocs
@UseGuards(JwtGuard)
@Controller('folders')
export class FoldersController {
  constructor(private readonly foldersService: FoldersService) {}

  @CreateFolderDocs
  @Post()
  @Public() // 해당 Route는 인증없이도 호출 가능
  async create(
    @GetUser('id') userId: Types.ObjectId,
    @Body() createFolderDto: MutateFolderDto,
  ) {
    await this.foldersService.create(userId, createFolderDto);
    return true;
  }
  • @GetUser 데코레이터 Failover처리
    • @GetUser에서 인증이 되지 않은 상태로 사용자 ID 호출 시도시 예외 반환하도록 수정
    // Expect Request, user property as type 'ReqUserPayload'(Refer to defined in common/types/type.d.ts)
    const user: Express.User = request.user;
   // 변경된 부분
    if (!user) {
      throw new UnauthorizedException('인증에 실패하였습니다.');
    }
    return user['id'];

PR 중점사항

리뷰어가 중점적으로 봐야하는 부분에 대해 적어주세요!

스크린샷

@github-actions github-actions bot added document 문서화 관련 작업 수정 및 생성 feature labels Jul 1, 2024
@J-Hoplin J-Hoplin added fix 버그 수정 and removed document 문서화 관련 작업 수정 및 생성 labels Jul 1, 2024
Copy link
Collaborator

@hye-on hye-on left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

고생했어!! 👍

@JonghunAn
Copy link
Member

LGTM~

* 특정 Route에 대해 Public을 허용할 수 있게 하기 위해 사용합니다.
*/

export const PublicRouteToken = 'public-route';
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

크게 상관은 없지만 요거 Symbol로 처리하는 게 좀 더 확실할 거 같은데 어때?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

적용 완료! Commit

@J-Hoplin J-Hoplin changed the base branch from development to dev-deploy July 20, 2024 06:21
@github-actions github-actions bot added the document 문서화 관련 작업 수정 및 생성 label Jul 20, 2024
@J-Hoplin J-Hoplin merged commit fc1269c into dev-deploy Jul 20, 2024
@J-Hoplin J-Hoplin deleted the feature/public-decorator branch July 20, 2024 06:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
document 문서화 관련 작업 수정 및 생성 feature fix 버그 수정
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants