Skip to content

Commit

Permalink
Merge pull request #22 from Ong-gi-Jong-gi/feature/TSK-35/lucky-bubble
Browse files Browse the repository at this point in the history
[TSK-35] : 행운이 상태, 말풍선 로직 구현
  • Loading branch information
pdh90345 authored Jul 9, 2024
2 parents 589317c + 126685e commit 4dbdd9c
Showing 1 changed file with 13 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,15 @@
import jakarta.servlet.http.HttpServletResponse;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import ongjong.namanmoo.domain.Member;
import ongjong.namanmoo.global.security.jwt.service.JwtService;
import ongjong.namanmoo.repository.MemberRepository;
import org.springframework.security.core.Authentication;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.web.authentication.SimpleUrlAuthenticationSuccessHandler;

import java.io.IOException;
import java.util.Optional;

@Slf4j
@RequiredArgsConstructor
Expand All @@ -28,19 +30,20 @@ public void onAuthenticationSuccess(HttpServletRequest request, HttpServletRespo
String refreshToken = jwtService.createRefreshToken();

jwtService.sendAccessAndRefreshToken(response, accessToken, refreshToken);
memberRepository.findByLoginId(loginId).ifPresent(
member -> {
member.setRefreshToken(refreshToken);
memberRepository.save(member);
}
);

log.info( "로그인에 성공합니다. loginId: {}" , loginId);
log.info( "AccessToken 을 발급합니다. AccessToken: {}" ,accessToken);
log.info( "RefreshToken 을 발급합니다. RefreshToken: {}" ,refreshToken);
// 한 번만 조회하여 재사용
Optional<Member> memberOptional = memberRepository.findByLoginId(loginId);
memberOptional.ifPresent(member -> {
member.setRefreshToken(refreshToken);
memberRepository.save(member);
});

log.info("로그인에 성공합니다. loginId: {}", loginId);
log.info("AccessToken 을 발급합니다. AccessToken: {}", accessToken);
log.info("RefreshToken 을 발급합니다. RefreshToken: {}", refreshToken);

// 사용자 정보를 포함한 JSON 응답 작성
memberRepository.findByLoginId(loginId).ifPresent(member -> {
memberOptional.ifPresent(member -> {
try {
response.setContentType("application/json");
response.setCharacterEncoding("UTF-8");
Expand All @@ -56,7 +59,6 @@ public void onAuthenticationSuccess(HttpServletRequest request, HttpServletRespo
log.error("JSON 응답 작성 중 오류 발생", e);
}
});

}

private String extractLoginId(Authentication authentication) {
Expand Down

0 comments on commit 4dbdd9c

Please sign in to comment.