You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
원래 @AuthenticationPrincipal으로 주입된 userDetails의 getUsername()이 실제 토큰에 저장된 사용자 식별자(이메일)가 아니라, CustomUserDetailsService에서 설정한 닉네임(사용자명)을 반환하기 때문에 인증에 실패.
JwtAuthenticationFilter는 JWT 토큰에서 이메일을 추출해 DB에서 사용자 정보를 조회하고, 그 이메일을 기준으로 인증 정보를 설정. 반면, CustomUserDetailsService에서는 getUsername()을 user.getUserName()으로 반환하도록 했기 때문에, @AuthenticationPrincipal으로 주입되는 값은 닉네임.
ProductService.getCurrentUser()는 이메일을 기준으로 사용자를 조회하도록 구현되어 있다면, userDetails.getUsername()으로 전달된 닉네임과 DB의 이메일 컬럼이 일치하지 않아 조회에 실패.
반면에, 수정한 코드는 HttpServletRequest에서 직접 토큰을 추출하고, jwtUtil.getUsernameFromToken(token)을 호출하여 실제 토큰에 저장된 이메일을 가져옴.
📄 설명
배경:
문제점:
✅ 작업할 내용
JwtAuthenticationFilter 수정:
TokenExtractor 클래스 추가:
컨트롤러 수정:
템플릿 수정:
🙋🏻 참고 자료
#176 #197
The text was updated successfully, but these errors were encountered: