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; } }