Skip to content

[9주차/주니] 워크북 제출합니다#57

Open
LeeJaeJun1 wants to merge 8 commits into
UMC-Inha:junny/mainfrom
LeeJaeJun1:main
Open

[9주차/주니] 워크북 제출합니다#57
LeeJaeJun1 wants to merge 8 commits into
UMC-Inha:junny/mainfrom
LeeJaeJun1:main

Conversation

@LeeJaeJun1
Copy link
Copy Markdown

@LeeJaeJun1 LeeJaeJun1 commented May 26, 2026

✅ 실습 체크리스트

  • 이론 학습을 완료하셨나요?
  • 미션 요구사항을 모두 이해하셨나요?
  • 실습을 수행하기 위한 공부를 완료하셨나요?
  • 실습 요구사항을 모두 완료하셨나요?

✅ 컨벤션 체크리스트

  • 디렉토리 구조 컨벤션을 잘 지켰나요?
  • pr 제목을 컨벤션에 맞게 작성하였나요?
  • pr에 해당되는 이슈를 연결하였나요?(중요)
  • 적절한 라벨을 설정하였나요?
  • 파트장에게 code review를 요청하기 위해 reviewer를 등록하였나요?
  • 닉네임/main 브랜치의 최신 상태를 반영하고 있는지 확인했나요?(매우 중요!)

📌 주안점

@LeeJaeJun1 LeeJaeJun1 requested a review from YoungJJun May 26, 2026 17:57
@LeeJaeJun1 LeeJaeJun1 self-assigned this May 26, 2026
@LeeJaeJun1 LeeJaeJun1 linked an issue May 26, 2026 that may be closed by this pull request
Copy link
Copy Markdown
Collaborator

@YoungJJun YoungJJun left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

9주차 피드백

  1. 먼저 미션 요구사항에 맞춰서 JWT 인증 필터 생성, SecurityConfig에 JWT 필터 삽입, 마이페이지에서 인증객체 받아서 처리하는 부분까지 잘 구현해주셨습니다!

  2. JwtUtil - createToken()

    .claim("uid", member.getMember().getSocialUid())
    .claim("social_type", member.getMember().getSocialType().name())

    이런 코드가 있습니다. OAuth와 별개로 JWT는 소셜 회원이 아닌 일반 회원에게도 사용되는 구조인데 소셜타입과 SocialUid가 존재할 수 있는지 체크가 필요할 것 같아요. 만약에 로컬회원이라 SocialUid같은 같이 nullable 처리되어 있으면 NPE 발생할 수 있어서 그렇습니다!

    이 부분은 DB 설계를 어떻게 바꾸셨는지 잘 모르겠어서 확실히 문제가 있다. 라고는 말씀드릴 수 없는데 현재 구조로 유지할거면 로컬 사용자의 SocialUid = id (memberId)를 할당하고 SocialType = LOCAL 이런식으로 설계해야 동작할 것 같아요.

    동일한 이유로 JwtAuthFilter에서도 uid, socialType이 null이 되어서 null인 사용자를 찾을 수 없기 때문에 MEMBER_NOT_FOUND (혹은 500) 등이 발생할 수 있을 것 같아요.

    String uid = jwtUtil.getUid(token);
    SocialType socialType = jwtUtil.getSocialType(token);
    
    loadUserByUidAndSocialType(socialType, uid)

    위에서 말씀드린 방법 이외의 방법으로 수정하고 싶으시면 아마 JWT로직을 소셜, 로컬 나눠서 구현해야 할 것 같아요.

  3. OAuthSuccessHandler - 불필요한 코드

    public void onAuthenticationSuccess(
    		HttpServletRequest request,
    		HttpServletResponse response,
    		Authentication authentication 
    	)

    → authentication을 주입받는 구조인데

    OAuthMember member = (OAuthMember) SecurityContextHolder
    	.getContext()
    	.getAuthentication()
    	.getPrincipal();
    	

    → ContextHolder부터 시작해서 다시 Authentication 으로 접근

    (OAuthMember) authentication.getPricipal()

    → 이렇게 주입받은거 그냥 바로 사용하면 될 것 같아요.

  4. Filter에 AuthMember 저장

    내용 설명을 쉽게하기 위해서 먼저 한 가지 설명드리면.. SecurityContext에는 memberId를 저장하거나 Member 객체를 저장하는 두 가지 방식이 있어요.

    Filter에서 사용자 찾아내고 해당 사용자 정보를 id만 저장하면 사용할 때 id꺼내서 findById해서 Member 객체를 가져오면되고 객체를 저장했으면 객체를 꺼내니까 바로 사용하면 되는 구조입니다.

    MemberQueryService
    
    @Transactional(readOnly = true)
    	public MemberResDTO.GetInfo getInfo(AuthMember authMember) {
    
    		Member member =  memberRepository.findById(authMember.getMember().getId())
    			.orElseThrow(() -> new MemberException(MemberErrorCode.MEMBER_NOT_FOUND));
    
    		return MemberConverter.toGetInfo(member);
    }

    해당 부분을 보시면 SecurityContext에 객체를 저장했으니까 AuthMember를 받아온 상황인데

     public MemberResDTO.GetInfo getInfo(AuthMember authMember) {
          return MemberConverter.toGetInfo(authMember.getMember());
      }

    이렇게 바로 .getMember에서 끝내버리는것과 비교했을 때 쿼리가 한 번 더 발생하는 문제가 있을 것 같아요. (안돌아가는건 아니고 성능문제 입니다!)


주니 소셜로그인까지 구현해주시고 너무 수고하셨습니다! 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Chapter09_Spring Security - JWT, OAuth

2 participants