content: package com.anita.multipleauthapi.security;
  
  import com.anita.multipleauthapi.model.entity.User;
  import com.anita.multipleauthapi.repository.UserRepository;
  import lombok.RequiredArgsConstructor;
  import org.springframework.security.core.userdetails.UserDetails;
  import org.springframework.security.core.userdetails.UserDetailsService;
  import org.springframework.security.core.userdetails.UsernameNotFoundException;
  import org.springframework.stereotype.Service;
  
  @Service
  @RequiredArgsConstructor
  public class CustomUserDetailsService implements UserDetailsService {
  
      private final UserRepository userRepository;
  
      @Override
      public UserDetails loadUserByUsername(String email) throws UsernameNotFoundException {
          User user = userRepository
                  .findByEmail(email)
                  .orElseThrow(() -> new UsernameNotFoundException(String.format("User not found with email: %s.", email)));
  
          return UserPrincipal.create(user);
      }
  
      public UserDetails loadUserById(Long id) {
          User user = userRepository
                  .findById(id)
                  .orElseThrow(() -> new UsernameNotFoundException(String.format("User not found with ID: %s.", id)));
  
          return UserPrincipal.create(user);
      }
  
  }
  