Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

♻️ refactor: 인증 payload 사용 방법 변경 #483

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

Open
asn6878 wants to merge 2 commits into main
base: main
Choose a base branch
Loading
from refactor/auth-req-type

Conversation

@asn6878
Copy link
Member

@asn6878 asn6878 commented Oct 30, 2025

📋 작업 내용

@CurrentUser 데코레이터 작성

기존에는 @Req req 를 controller 메서드의 인자로 전달받아 req.user 형태로 사용했지만, payload의 타입과 의도를 명확하게 하기 위하여 별도 데코레이터를 생성하였습니다.

동작 흐름을 간략화시 다음과 같이 진행됩니다.

Guard (JwtGuard) ← 여기서 Passport가 JWT 검증하고 request.user 주입
Interceptor
Parameter Decorator (@CurrentUser()) ← 여기서 request.user 읽음
Controller Handler

사용자 인증 payload 접근 방법 변경

변경된 스펙에 맞게 기존에 존재하던 인증 엔드포인트들을 수정 하였습니다.

@asn6878 asn6878 self-assigned this Oct 30, 2025
@asn6878 asn6878 added ✨ Feature 기능 구현 🔨 Refactor 리팩토링 (구조 변경) labels Oct 30, 2025
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR refactors authentication handling across controllers by replacing direct access to req.user with a custom @CurrentUser() decorator. This improves code consistency and type safety.

  • Introduces a new @CurrentUser() decorator to extract user information from requests
  • Replaces all instances of @Req() req with @CurrentUser() user: Payload across controllers
  • Removes unnecessary Number.parseInt() conversion in file controller

Reviewed Changes

Copilot reviewed 7 out of 7 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
server/src/common/decorator/current-user.decorator.ts Creates the new @CurrentUser() decorator that extracts user from request context
server/src/common/decorator/index.ts Exports the current-user decorator for use across the application
server/src/user/controller/user.controller.ts Replaces req.user with @CurrentUser() decorator in refresh token and update profile endpoints
server/src/like/controller/like.controller.ts Replaces req.user with @CurrentUser() decorator in get, create, and delete like endpoints
server/src/like/service/like.service.ts Updates get method signature to accept Payload | null for optional authentication
server/src/file/controller/file.controller.ts Replaces req.user with @CurrentUser() decorator and removes unnecessary Number.parseInt()
server/src/comment/controller/comment.controller.ts Replaces req.user with @CurrentUser() decorator in create, delete, and update comment endpoints

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

return ApiResponse.responseWithData(
'파일 업로드에 성공했습니다.',
await this.fileService.create(file, Number.parseInt(req.user.id)),
await this.fileService.create(file, user.id),
Copy link

Copilot AI Oct 30, 2025

Choose a reason for hiding this comment

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

The user.id is of type number according to the Payload type definition. However, the old code used Number.parseInt(req.user.id), suggesting that user.id might be a string at runtime. If user.id is actually a string in the JWT payload, this could cause a type mismatch when calling fileService.create() which expects a number. Verify that the JWT payload parsing correctly converts the ID to a number, or add explicit type conversion here.

Suggested change
await this.fileService.create(file, user.id),
await this.fileService.create(file, Number(user.id)),

Copilot uses AI. Check for mistakes.
Copy link
Member

@Jo-Minseok Jo-Minseok left a comment

Choose a reason for hiding this comment

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

LGTM!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

Copilot code review Copilot Copilot left review comments

@Jo-Minseok Jo-Minseok Jo-Minseok approved these changes

@CodeVac513 CodeVac513 Awaiting requested review from CodeVac513

Labels

✨ Feature 기능 구현 🔨 Refactor 리팩토링 (구조 변경)

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

AltStyle によって変換されたページ (->オリジナル) /