From acba33d8857ea9c5a3fa135a464b9e11e9bb2f27 Mon Sep 17 00:00:00 2001 From: toychip Date: Sun, 14 Jan 2024 15:06:37 +0900 Subject: [PATCH] =?UTF-8?q?fix:=20=EA=B8=B0=EB=B3=B8=20=EC=98=88=EC=99=B8?= =?UTF-8?q?=EC=B2=98=EB=A6=AC=EC=97=90=EC=84=9C=20member=EB=A1=9C=20?= =?UTF-8?q?=EB=B0=94=EA=BF=94=20=EC=97=90=EB=9F=AC=20=EB=A1=9C=EA=B7=B8=20?= =?UTF-8?q?=EC=B6=9C=EB=A0=A5=EB=90=98=EB=8F=84=EB=A1=9D=20=EC=88=98?= =?UTF-8?q?=EC=A0=95=20(#38)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../security/oauth2/CustomOAuthSuccessHandler.java | 4 +++- .../com/api/TaveShot/global/util/SecurityUtil.java | 10 +++++----- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/src/main/java/com/api/TaveShot/global/security/oauth2/CustomOAuthSuccessHandler.java b/src/main/java/com/api/TaveShot/global/security/oauth2/CustomOAuthSuccessHandler.java index 6442e12..17b02ac 100644 --- a/src/main/java/com/api/TaveShot/global/security/oauth2/CustomOAuthSuccessHandler.java +++ b/src/main/java/com/api/TaveShot/global/security/oauth2/CustomOAuthSuccessHandler.java @@ -44,12 +44,14 @@ public void onAuthenticationSuccess(final HttpServletRequest request, final Http log.info("------------------ 소셜 로그인 성공: " + loginId); Integer id = githubUserInfo.getId(); + log.info("------------------ id = " + id); + String mail = githubUserInfo.getMail(); String profileImageUrl = githubUserInfo.getProfileImageUrl(); Member loginMember = memberRepository.findByGitId(Long.valueOf(id)).orElseThrow( () -> new ApiException(_SERVER_USER_NOT_FOUND)); - String loginMemberId = String.valueOf(loginMember.getId()); + String loginMemberId = String.valueOf(loginMember.getGitId()); String token = generateToken(loginMemberId); diff --git a/src/main/java/com/api/TaveShot/global/util/SecurityUtil.java b/src/main/java/com/api/TaveShot/global/util/SecurityUtil.java index b7d1501..0a9ecd5 100644 --- a/src/main/java/com/api/TaveShot/global/util/SecurityUtil.java +++ b/src/main/java/com/api/TaveShot/global/util/SecurityUtil.java @@ -10,6 +10,10 @@ public class SecurityUtil { public static Member getCurrentMember() { Authentication authentication = SecurityContextHolder.getContext().getAuthentication(); + System.out.println("authentication = " + authentication.getName()); + System.out.println("authentication.getPrincipal() = " + authentication.getPrincipal()); + System.out.println("authentication.getAuthorities() = " + authentication.getAuthorities()); + if (authentication == null || !authentication.isAuthenticated()) { throw new ApiException(ErrorType._UNAUTHORIZED); @@ -17,10 +21,6 @@ public static Member getCurrentMember() { Object principal = authentication.getPrincipal(); - if (principal instanceof Member) { - return (Member) principal; - } - - throw new ApiException(ErrorType._USER_NOT_FOUND_DB); + return (Member) principal; } }