[9주차/세라] 워크북 제출합니다#20
Open
Seojin5 wants to merge 6 commits into
Open
Conversation
seoki180
approved these changes
Jun 2, 2026
Comment on lines
+20
to
+29
| @Body() body: UserSignUpRequest, | ||
| ): Promise<ApiResponse<any>> { | ||
|
|
||
| const result = await userSignUp(body); | ||
|
|
||
| this.setStatus(201); | ||
|
|
||
| return ApiResponse.success( | ||
| 201, | ||
| "회원가입 성공", |
Collaborator
There was a problem hiding this comment.
응답 성공 형식을 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); |
Collaborator
There was a problem hiding this comment.
해당 컨트롤러는 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, "토큰 형식 오류"); | ||
| } |
Collaborator
There was a problem hiding this comment.
jwt 토큰은 자주 만료가 되니 만료되었음을 확인하는 로직을 추가해주시면 좋을거 같습니다
Comment on lines
+32
to
+34
| (req as any).user = { | ||
| userId: decoded.userId, | ||
| }; |
Collaborator
There was a problem hiding this comment.
Ts 에서 req.user를 접근하려면 전역 express.d.ts 설정에 추가를 해서 express 타입을 확장해야합니다.
src/types/express.d.ts
declare global {
namespace Express {
interface Request {
user?: {
userId: number;
};
}
}
}
export {};
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
✅ 실습 체크리스트
✅ 컨벤션 체크리스트