Skip to content

Commit

Permalink
fix: 기본 예외처리에서 member로 바꿔 에러 로그 출력되도록 수정 (#38)
Browse files Browse the repository at this point in the history
  • Loading branch information
toychip committed Jan 14, 2024
1 parent 0ff7a3e commit acba33d
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
10 changes: 5 additions & 5 deletions src/main/java/com/api/TaveShot/global/util/SecurityUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,17 @@ 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);
}

Object principal = authentication.getPrincipal();

if (principal instanceof Member) {
return (Member) principal;
}

throw new ApiException(ErrorType._USER_NOT_FOUND_DB);
return (Member) principal;
}
}

0 comments on commit acba33d

Please sign in to comment.