Skip to content

Commit

Permalink
refactor: 닉네임 처리 수정
Browse files Browse the repository at this point in the history
  • Loading branch information
nyeroni committed Nov 14, 2024
1 parent 20b1ef0 commit 3b6f7f1
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ public ResponseEntity<LoginStatusResponse> checkLoginStatus(HttpServletRequest r
.body(new LoginStatusResponse(false, false, "사용자는 로그인 상태가 아닙니다."));
}

boolean hasNickname = authService.hasNickname(null);
boolean hasNickname = authService.hasNickname();
String message = hasNickname ? "사용자는 완벽하게 회원가입 후 로그인된 상태입니다." :
"닉네임이 없는 상태로 회원가입이 완료되었습니다. 닉네임 입력이 필요합니다.";

Expand Down Expand Up @@ -155,8 +155,7 @@ public ResponseEntity<?> logout(Principal principal, HttpServletRequest request)
return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(Map.of("error", "유효하지 않은 토큰입니다."));
}

String socialId = SecurityContextHolder.getContext().getAuthentication().getName();
MemberLogoutResponse memberLogoutResponse = authService.logout(socialId);
MemberLogoutResponse memberLogoutResponse = authService.logout();
if (memberLogoutResponse == null) {
log.warn("Social Id {}로 회원을 찾을 수 없음", principal.getName());
return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(Map.of("error", "Social Id로 회원을 찾을 수 없습니다."));
Expand Down
13 changes: 7 additions & 6 deletions src/main/java/yerong/wedle/oauth/service/AuthService.java
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ public LoginResponse login(MemberRequest memberRequest){
}
redisTemplate.opsForValue().set("RT:" + member.getSocialId(), tokenResponse.getRefreshToken(), tokenResponse.getRefreshTokenExpiresIn(), TimeUnit.MILLISECONDS);

return new LoginResponse(tokenResponse.getAccessToken(), tokenResponse.getRefreshToken(), member.isExistingMember(), hasNickname(member.getSocialId()));
return new LoginResponse(tokenResponse.getAccessToken(), tokenResponse.getRefreshToken(), member.isExistingMember(), hasNickname());
}
@Transactional
public TokenResponse refreshAccessToken(String refreshTokenValue){
Expand Down Expand Up @@ -114,15 +114,16 @@ public boolean isLoggedIn() {
return socialId != null && memberRepository.findBySocialId(socialId).isPresent();
}

public boolean hasNickname(String socialId) {
if(socialId == null) {
socialId = SecurityContextHolder.getContext().getAuthentication().getName();
}
public boolean hasNickname() {
String socialId = SecurityContextHolder.getContext().getAuthentication().getName();

Member member = memberRepository.findBySocialId(socialId).orElse(null);
return member.getNickname() != null;
}
@Transactional
public MemberLogoutResponse logout(String socialId) {
public MemberLogoutResponse logout() {
String socialId = SecurityContextHolder.getContext().getAuthentication().getName();

Member member = memberRepository.findBySocialId(socialId)
.orElseThrow(MemberNotFoundException::new);
RefreshToken refreshToken = refreshTokenRepository.findByMemberId(member.getMemberId())
Expand Down

0 comments on commit 3b6f7f1

Please sign in to comment.