From 3b6f7f1c06ba5721ab022ee095f53e585689f00a Mon Sep 17 00:00:00 2001 From: Sin Ye Rin <91180366+nyeroni@users.noreply.github.com> Date: Thu, 14 Nov 2024 15:26:11 +0900 Subject: [PATCH] =?UTF-8?q?refactor:=20=EB=8B=89=EB=84=A4=EC=9E=84=20?= =?UTF-8?q?=EC=B2=98=EB=A6=AC=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../wedle/oauth/controller/LoginController.java | 5 ++--- .../yerong/wedle/oauth/service/AuthService.java | 13 +++++++------ 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/src/main/java/yerong/wedle/oauth/controller/LoginController.java b/src/main/java/yerong/wedle/oauth/controller/LoginController.java index 6e17c97..af0b014 100644 --- a/src/main/java/yerong/wedle/oauth/controller/LoginController.java +++ b/src/main/java/yerong/wedle/oauth/controller/LoginController.java @@ -104,7 +104,7 @@ public ResponseEntity checkLoginStatus(HttpServletRequest r .body(new LoginStatusResponse(false, false, "사용자는 로그인 상태가 아닙니다.")); } - boolean hasNickname = authService.hasNickname(null); + boolean hasNickname = authService.hasNickname(); String message = hasNickname ? "사용자는 완벽하게 회원가입 후 로그인된 상태입니다." : "닉네임이 없는 상태로 회원가입이 완료되었습니다. 닉네임 입력이 필요합니다."; @@ -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로 회원을 찾을 수 없습니다.")); diff --git a/src/main/java/yerong/wedle/oauth/service/AuthService.java b/src/main/java/yerong/wedle/oauth/service/AuthService.java index ccf8e73..2756e6d 100644 --- a/src/main/java/yerong/wedle/oauth/service/AuthService.java +++ b/src/main/java/yerong/wedle/oauth/service/AuthService.java @@ -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){ @@ -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())