Express 임경민 미션 10#10
Closed
play-ancora-gyungmin wants to merge 17 commits intocodeit-sprint-fullstack:express-임경민from
Hidden character warning
The head ref may contain hidden characters: "express-\uc784\uacbd\ubbfc"
Closed
Express 임경민 미션 10#10play-ancora-gyungmin wants to merge 17 commits intocodeit-sprint-fullstack:express-임경민from
play-ancora-gyungmin wants to merge 17 commits intocodeit-sprint-fullstack:express-임경민from
Conversation
pers0n4
approved these changes
Dec 3, 2025
Comment on lines
+6
to
+16
| const { email, nickname, password } = req.body; | ||
|
|
||
| if (!email || !emailRegex.test(email)) { | ||
| throw new BadRequestException('유효한 이메일 형식이 아닙니다.'); | ||
| } | ||
| if (!nickname) { | ||
| throw new BadRequestException('이름을 입력해주세요.'); | ||
| } | ||
| if (!password || password.length < 6) { | ||
| throw new BadRequestException('비밀번호는 6자 이상이어야 합니다.'); | ||
| } |
Collaborator
There was a problem hiding this comment.
zod를 사용하지 않고 있었다면 그냥 넘겼을 것 같은 부분인데, 현재 프로젝트에서 이미 zod를 사용하고 있으니 검증 로직을 전부 zod 스키마에서 수행하게 만들면 좋을 것 같네요.
Collaborator
There was a problem hiding this comment.
데이터 검증은 zod로 처리하고 zod에서 발생하는 error를 캐치하는 핸들러를 하나 만들어서 express 미들웨어로 씌우거나 하는 방식으로 처리할 수도 있을 것 같습니다.
src/services/users.services.js
Outdated
Collaborator
There was a problem hiding this comment.
빈 파일은 아직 구현이 안 된 부분인 걸까요?
Comment on lines
14
to
18
| const page = parseInt(req.query.page, 10) || 1; | ||
| const pageSize = parseInt(req.query.pageSize, 10) || 10; | ||
| const pageSize = | ||
| parseInt(req.query.pageSize, 10) || Number.MAX_SAFE_INTEGER; | ||
| const keyword = req.query.keyword; | ||
| const orderBy = req.query.orderBy; |
Collaborator
There was a problem hiding this comment.
req.query에서 데이터를 가져오는 부분도 zod로 처리하면 어떨까요?
Comment on lines
+15
to
+68
| try { | ||
| const { authorization } = req.cookies; | ||
| if (!authorization) { | ||
| throw new UnauthorizedException('인증 정보가 없습니다.'); | ||
| } | ||
| const [tokenType, token] = authorization.split(' '); | ||
| if (tokenType !== 'Bearer' || !token) { | ||
| throw new UnauthorizedException('지원하지 않는 인증 방식입니다.'); | ||
| } | ||
|
|
||
| let decoded = verifyToken(token); | ||
|
|
||
| // Access Token이 만료된 경우 | ||
| if (!decoded) { | ||
| const { refreshToken: refreshTokenWithBearer } = req.cookies; | ||
| if (!refreshTokenWithBearer) { | ||
| throw new UnauthorizedException('인증 정보가 만료되었습니다.'); | ||
| } | ||
|
|
||
| const [refreshTokenType, refreshToken] = | ||
| refreshTokenWithBearer.split(' '); | ||
| if (refreshTokenType !== 'Bearer' || !refreshToken) { | ||
| throw new UnauthorizedException('지원하지 않는 인증 방식입니다.'); | ||
| } | ||
|
|
||
| const decodedRefreshToken = verifyToken(refreshToken); | ||
| if (!decodedRefreshToken) { | ||
| throw new UnauthorizedException('인증 정보가 만료되었습니다.'); | ||
| } | ||
|
|
||
| const user = await usersRepository.findUserById( | ||
| decodedRefreshToken.userId, | ||
| ); | ||
| if (!user || user.refreshToken !== refreshToken) { | ||
| throw new UnauthorizedException('인증 정보가 유효하지 않습니다.'); | ||
| } | ||
|
|
||
| // 새로운 Access Token 발급 | ||
| const newAccessToken = jwt.sign({ userId: user.id }, config.JWT_SECRET, { | ||
| expiresIn: '6h', | ||
| }); | ||
|
|
||
| res.cookie('authorization', `Bearer ${newAccessToken}`); | ||
| decoded = verifyToken(newAccessToken); | ||
| } | ||
|
|
||
| const user = await usersRepository.findUserById(decoded.userId); | ||
| if (!user) { | ||
| throw new UnauthorizedException( | ||
| '인증 정보와 일치하는 사용자가 없습니다.', | ||
| ); | ||
| } | ||
| req.user = user; | ||
| next(); |
Comment on lines
+79
to
+81
| function Grogu() {} | ||
|
|
||
| Grogu(); |
Comment on lines
+74
to
+75
| // Refresh Token을 DB에 저장 | ||
| await usersRepository.updateUserById(user.id, { refreshToken }); |
Collaborator
There was a problem hiding this comment.
권한 회수를 목적으로 refresh token을 db에 저장하는 경우 refresh token은 user 모델에 넣어두기보다는 다중 기기 사용 등의 시나리오에 대응하기 위해 별도의 모델(테이블)로 분리하는 것이 좋습니다.
e.g. PC와 모바일에서 동시에 로그인을 한다면?
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.
요구사항
백엔드 구현 요구사항
상품 등록
상품 상세
좋아요 기능
에러 처리
인증
상품 기능 인가
게시글 기능 인가
댓글 기능 인가
심화 요구사항
상태코드 (웹 API 관련)
인증