Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 10 additions & 6 deletions user/src/main/java/com/homeaid/service/UserServiceImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,11 @@
import com.homeaid.security.JwtUtil;
import jakarta.validation.Valid;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
import org.springframework.stereotype.Service;

@Slf4j
@Service
@RequiredArgsConstructor
public class UserServiceImpl implements UserService {
Expand Down Expand Up @@ -49,15 +51,17 @@ public User getUserById(Long id) {
}

public String loginAndGetToken(SignInRequestDto request) {
var user = userRepository.findByEmail(request.getEmail())
.orElseThrow(() -> new CustomException(UserErrorCode.LOGIN_FAILED));
var user = userRepository.findByEmail(request.getEmail());
if (user.isEmpty()) {
log.warn("Login failed - User not found: email={}", request.getEmail());
throw new CustomException(UserErrorCode.LOGIN_FAILED);
}

if (!passwordEncoder.matches(request.getPassword(), user.getPassword())) {
if (!passwordEncoder.matches(request.getPassword(), user.get().getPassword())) {
log.warn("Login failed - Invalid password: email={}", request.getEmail());
throw new CustomException(UserErrorCode.LOGIN_FAILED);
}

return jwtUtil.createJwt(user.getId(), user.getEmail(), user.getRole().name(), 1800000L);
return jwtUtil.createJwt(user.get().getId(), user.get().getEmail(), user.get().getRole().name(), 3600000L); // 1시간
}


}