Skip to content

Commit

Permalink
♻️ refactor: @authuser 수정 (#105)
Browse files Browse the repository at this point in the history
♻️ refactor: @authuser 수정 (#105)
  • Loading branch information
jinho7 authored Jun 2, 2024
2 parents a22e5fe + 0b38fa5 commit fcc7374
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ public GatewayFilter apply(Config config) {

// Mono(단일 값), Flux(다중 값) -> Spring WebFlux
private Mono<Void> onError(ServerWebExchange exchange, String errorMsg) {
log.error(errorMsg);
log.error("[*] Gateway filter error: {}", errorMsg);

ServerHttpResponse response = exchange.getResponse();
response.setStatusCode(HttpStatus.UNAUTHORIZED);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import com.waither.userservice.entity.User;
import com.waither.userservice.global.jwt.execption.SecurityCustomException;
import com.waither.userservice.global.jwt.execption.SecurityErrorCode;
import com.waither.userservice.global.jwt.util.JwtUtil;
import com.waither.userservice.repository.UserRepository;
import jakarta.servlet.http.HttpServletRequest;
import org.springframework.core.MethodParameter;
Expand All @@ -23,7 +22,6 @@
@Transactional
public class AuthUserArgumentResolver implements HandlerMethodArgumentResolver {

private final JwtUtil jwtUtil;
private final UserRepository userRepository;

@Override
Expand All @@ -37,10 +35,11 @@ public boolean supportsParameter(MethodParameter parameter) {
public Object resolveArgument(MethodParameter parameter, ModelAndViewContainer mavContainer,
NativeWebRequest webRequest, WebDataBinderFactory binderFactory) {
HttpServletRequest httpServletRequest = (HttpServletRequest) webRequest.getNativeRequest();
String token = jwtUtil.resolveAccessToken(httpServletRequest);
String email = jwtUtil.getEmail(token);
String email = httpServletRequest.getHeader("email");

log.info("[*] Header <email> from ApiGateway: {}", email);

return userRepository.findByEmail(email)
.orElseThrow(() -> new SecurityCustomException(SecurityErrorCode.TOKEN_NOT_FOUND));
.orElseThrow(() -> new SecurityCustomException(SecurityErrorCode.USER_NOT_FOUND));
}
}
}

0 comments on commit fcc7374

Please sign in to comment.