Skip to content

[9주차/세라] 워크북 제출합니다#20

Open
Seojin5 wants to merge 6 commits into
UMC-Inha:sera/mainfrom
Seojin5:feature/chapter-09
Open

[9주차/세라] 워크북 제출합니다#20
Seojin5 wants to merge 6 commits into
UMC-Inha:sera/mainfrom
Seojin5:feature/chapter-09

Conversation

@Seojin5
Copy link
Copy Markdown

@Seojin5 Seojin5 commented May 27, 2026

✅ 실습 체크리스트

  • 이론 학습을 완료하셨나요?
  • 미션 요구사항을 모두 이해하셨나요?
  • 실습을 수행하기 위한 공부를 완료하셨나요?
  • 실습 요구사항을 모두 완료하셨나요?

✅ 컨벤션 체크리스트

  • 디렉토리 구조 컨벤션을 잘 지켰나요?
  • pr 제목을 컨벤션에 맞게 작성하였나요?
  • pr에 해당되는 이슈를 연결하였나요?(중요)
  • 적절한 라벨을 설정하였나요?
  • 파트장에게 code review를 요청하기 위해 reviewer를 등록하였나요?
  • 닉네임/main 브랜치의 최신 상태를 반영하고 있는지 확인했나요?(매우 중요!)

@Seojin5 Seojin5 requested a review from seoki180 May 27, 2026 18:32
Comment on lines +20 to +29
@Body() body: UserSignUpRequest,
): Promise<ApiResponse<any>> {

const result = await userSignUp(body);

this.setStatus(201);

return ApiResponse.success(
201,
"회원가입 성공",
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

응답 성공 형식을 dto로 선언해서 리턴타입에도 명시하면 좋을거 같습니다!

public async signup(
  @Body() body: UserSignUpRequest,
): Promise<ApiResponse<UserSignUpResponse>> {
  const result = await userSignUp(body);
  this.setStatus(201);
  return ApiResponse.success(201, "회원가입 성공", result);
}

Comment on lines +42 to +66
return new Promise((resolve, reject) => {
passport.authenticate("local", (err: any, user: any) => {

if (err || !user) {
return reject(new Error("로그인 실패"));
}

const token = jwt.sign(
{ userId: user.userId },
process.env.JWT_SECRET!,
{ expiresIn: "1h" },
);

resolve(
ApiResponse.success(
200,
"로그인 성공",
{
token,
user,
},
),
);

})({ body } as any);
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

해당 컨트롤러는 passport.authneticate 미들웨어만 거치고 이외의 로직을 수행하지 않습니다.

passport.authenticate를 미들웨어함수로 선언하고 @Middleware를 사용해 코드로직을 간결하게 사용하는게 좋아보입니다.

@Middleware(LocalLogin)
@Post("/login")
...
...
const user = req.user
return await this.userService.login(user) // 로그인에 필요한 로직 수행 

Comment on lines +23 to +25
if (!token) {
throw new CustomError(401, "토큰 형식 오류");
}
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

jwt 토큰은 자주 만료가 되니 만료되었음을 확인하는 로직을 추가해주시면 좋을거 같습니다

Comment on lines +32 to +34
(req as any).user = {
userId: decoded.userId,
};
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Ts 에서 req.user를 접근하려면 전역 express.d.ts 설정에 추가를 해서 express 타입을 확장해야합니다.

src/types/express.d.ts

declare global {
  namespace Express {
    interface Request {
      user?: {
        userId: number;
      };
    }
  }
}

export {};

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants