diff --git a/src/main/java/leets/weeth/global/auth/jwt/filter/JwtAuthenticationProcessingFilter.java b/src/main/java/leets/weeth/global/auth/jwt/filter/JwtAuthenticationProcessingFilter.java index 38e687d6..948bc2eb 100644 --- a/src/main/java/leets/weeth/global/auth/jwt/filter/JwtAuthenticationProcessingFilter.java +++ b/src/main/java/leets/weeth/global/auth/jwt/filter/JwtAuthenticationProcessingFilter.java @@ -52,23 +52,20 @@ protected void doFilterInternal(HttpServletRequest request, HttpServletResponse public void checkAccessTokenAndRefreshToken(HttpServletRequest request, HttpServletResponse response, FilterChain filterChain, String refreshToken) throws ServletException, IOException { log.info("checkAccessTokenAndRefreshToken() 호출"); - jwtService.extractAccessToken(request) + + String accessToken = jwtService.extractAccessToken(request) .filter(jwtService::isTokenValid) - .ifPresentOrElse( - accessToken -> jwtService.extractEmail(accessToken) - .ifPresent(email -> userRepository.findByEmail(email) - .ifPresent(user -> { - saveAuthentication(user); - try { - filterChain.doFilter(request, response); - } catch (IOException | ServletException e) { - throw new RuntimeException(e); - } - })), - () -> checkRefreshTokenAndReIssueAccessToken(response, refreshToken) - ); + .orElse(null); - filterChain.doFilter(request, response); + if (accessToken == null) { + checkRefreshTokenAndReIssueAccessToken(response, refreshToken); + } else { + jwtService.extractEmail(accessToken) + .ifPresent(email -> userRepository.findByEmail(email) + .ifPresent(this::saveAuthentication)); + + filterChain.doFilter(request, response); + } } public void checkRefreshTokenAndReIssueAccessToken(HttpServletResponse response, String refreshToken) {