-
Notifications
You must be signed in to change notification settings - Fork 2
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
Feat/#462 닉네임 변경 API 구현 #470
base: main
Are you sure you want to change the base?
Changes from 7 commits
9ef006e
95bd4c7
ee8bc8a
3d14050
ded41a5
d52d13c
9bfb040
621a625
4685592
5a64990
2847c8d
05fdcf1
514c475
f0e54f9
04af872
3d46182
72ea86a
d9115bf
21358a7
8ca6f07
9c6fc11
21f4d60
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -43,6 +43,7 @@ public Member register(final String email) { | |
final Member newMember = new Member(email, BASIC_NICKNAME); | ||
final Member savedMember = memberRepository.save(newMember); | ||
savedMember.updateNickname(savedMember.getNickname() + savedMember.getId()); | ||
|
||
return savedMember; | ||
} | ||
|
||
|
@@ -63,10 +64,7 @@ public Member findByIdAndNicknameThrowIfNotExist(final Long id, final Nickname n | |
public void deleteById(final Long id, final MemberInfo memberInfo) { | ||
final Member member = getMemberIfValidRequest(id, memberInfo); | ||
|
||
final List<KillingPartLike> membersExistLikes = likeRepository.findAllByMemberAndIsDeleted( | ||
member, | ||
false | ||
); | ||
final List<KillingPartLike> membersExistLikes = likeRepository.findAllByMemberAndIsDeleted(member, false); | ||
|
||
membersExistLikes.forEach(KillingPartLike::updateDeletion); | ||
commentRepository.deleteAllByMember(member); | ||
|
@@ -77,16 +75,9 @@ private Member getMemberIfValidRequest(final Long memberId, final MemberInfo mem | |
final long requestMemberId = memberInfo.getMemberId(); | ||
final Member requestMember = findById(requestMemberId); | ||
final Member targetMember = findById(memberId); | ||
|
||
validateMemberAuthentication(requestMember, targetMember); | ||
return targetMember; | ||
} | ||
|
||
private Member findById(final Long id) { | ||
return memberRepository.findById(id) | ||
.orElseThrow(() -> new MemberException.MemberNotExistException( | ||
Map.of("Id", String.valueOf(id)) | ||
)); | ||
return targetMember; | ||
} | ||
|
||
private void validateMemberAuthentication(final Member requestMember, final Member targetMember) { | ||
|
@@ -100,13 +91,20 @@ private void validateMemberAuthentication(final Member requestMember, final Memb | |
} | ||
} | ||
|
||
private Member findById(final Long id) { | ||
return memberRepository.findById(id) | ||
.orElseThrow(() -> new MemberException.MemberNotExistException( | ||
Map.of("Id", String.valueOf(id)) | ||
)); | ||
} | ||
|
||
@Transactional | ||
public TokenPair updateNickname(final Long memberId, final MemberInfo memberInfo, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 닉네임 변경으로 인해 토큰 재발급이 일어나고, 응답이 반환되는 보안 문제가 걱정된다면 닉네임 같은 개인정보를 바꾼 후에 재로그인을 요청하는 것은 어떨까요? 닉네임이 변경되면 서버 내부적으로 TOKEN을 삭제 -> 로그인이 만료된 것 처럼 취급이 되어서 프론트엔드에서 자연스럽게 재로그인을 요청하도록 하는 것은 어떤가요? |
||
final NicknameUpdateRequest request) { | ||
final NicknameUpdateRequest request) { | ||
final Member member = getMemberIfValidRequest(memberId, memberInfo); | ||
final Nickname nickname = new Nickname(request.getNickname()); | ||
|
||
if (isSameNickname(member, nickname)) { | ||
if (member.hasSameNickname(nickname)) { | ||
return null; | ||
} | ||
|
||
|
@@ -121,15 +119,8 @@ private TokenPair reissueTokenPair(final Long memberId, final String nickname) { | |
final String reissuedAccessToken = tokenProvider.createAccessToken(memberId, nickname); | ||
final String reissuedRefreshToken = tokenProvider.createRefreshToken(memberId, nickname); | ||
inMemoryTokenPairRepository.addOrUpdateTokenPair(reissuedRefreshToken, reissuedAccessToken); | ||
return new TokenPair(reissuedAccessToken, reissuedRefreshToken); | ||
} | ||
|
||
|
||
private boolean isSameNickname(final Member member, final Nickname nickname) { | ||
final String originalNickname = member.getNickname(); | ||
final String nicknameForUpdate = nickname.getValue(); | ||
|
||
return originalNickname.equals(nicknameForUpdate); | ||
return new TokenPair(reissuedAccessToken, reissuedRefreshToken); | ||
} | ||
|
||
private void validateDuplicateNickname(final Nickname nickname) { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,6 +2,7 @@ | |
|
||
import jakarta.servlet.http.Cookie; | ||
import jakarta.servlet.http.HttpServletResponse; | ||
import jakarta.validation.Valid; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.http.HttpStatus; | ||
import org.springframework.http.ResponseEntity; | ||
|
@@ -42,7 +43,7 @@ public ResponseEntity<Void> deleteMember( | |
public ResponseEntity<ReissueAccessTokenResponse> updateNickname( | ||
@PathVariable(name = "member_id") final Long memberId, | ||
@Authenticated final MemberInfo memberInfo, | ||
@RequestBody final NicknameUpdateRequest request, | ||
@Valid @RequestBody final NicknameUpdateRequest request, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 저도 매의 눈을 뜨기 위해 노력할게요 🦅 👀 |
||
final HttpServletResponse response | ||
) { | ||
final TokenPair tokenPair = memberService.updateNickname(memberId, memberInfo, request); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
메서드 순서 변경이 필요해 보입니다! 이 메서드를 위로 올리는 것은 어떨까요?