이 PR에서는 기존 User 데이터를 Repository에서 불러오는 로직을 Authentication에서 가져오는 로직으로 수정합니다.
Authentication 객체가 생성될 때, UserDetails 객체를 포함함으로써 사용자에 대한 모든 필요한 정보를 저장할 수 있습니다.
Spring Security는 ThreadLocal 변수 안에 SecurityContextHolder를 저장합니다.
그리고 인증된 사용자의 Authentication 객체는 SecurityContextHolder에 저장됩니다. 이를 통해 현재 인증된 사용자의 정보를 애플리케이션 어디서든 접근할 수 있습니다.
@Bean
public UserDetailsService userDetailsService() {
return email -> userRepository.findByEmail(email)
.orElseThrow(() -> new NotFoundExceptionMapper(ErrorMessage.USER_NAME_NOT_FOUND, email));
}
로그인 인증 과정에서 이 코드에서 이미 User 데이터를 불러오기 때문에 다시 Repository에서 User를 불러올 필요가 없습니다.
이 PR에서는 기존 User 데이터를 Repository에서 불러오는 로직을 Authentication에서 가져오는 로직으로 수정합니다.
Authentication 객체가 생성될 때, UserDetails 객체를 포함함으로써 사용자에 대한 모든 필요한 정보를 저장할 수 있습니다. Spring Security는 ThreadLocal 변수 안에 SecurityContextHolder를 저장합니다. 그리고 인증된 사용자의 Authentication 객체는 SecurityContextHolder에 저장됩니다. 이를 통해 현재 인증된 사용자의 정보를 애플리케이션 어디서든 접근할 수 있습니다.
로그인 인증 과정에서 이 코드에서 이미 User 데이터를 불러오기 때문에 다시 Repository에서 User를 불러올 필요가 없습니다.