From ba8da129c788026857267ef7be3ffdedc7ae6a77 Mon Sep 17 00:00:00 2001 From: nohy6630 Date: Sat, 18 May 2024 15:47:56 +0900 Subject: [PATCH] =?UTF-8?q?Fix:=20=EB=A9=94=EC=9D=B8=ED=8E=98=EC=9D=B4?= =?UTF-8?q?=EC=A7=80=20=EB=B9=84=EB=A1=9C=EA=B7=B8=EC=9D=B8=EC=8B=9C=20?= =?UTF-8?q?=EC=9E=91=EB=8F=99=ED=95=98=EB=8F=84=EB=A1=9D=20=EC=88=98?= =?UTF-8?q?=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../backend/domain/auth/jwt/SecurityContextProvider.java | 4 ++++ .../meetup/teame/backend/domain/user/service/UserService.java | 4 +++- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/src/main/java/com/meetup/teame/backend/domain/auth/jwt/SecurityContextProvider.java b/src/main/java/com/meetup/teame/backend/domain/auth/jwt/SecurityContextProvider.java index ee5b3c6..513eef4 100644 --- a/src/main/java/com/meetup/teame/backend/domain/auth/jwt/SecurityContextProvider.java +++ b/src/main/java/com/meetup/teame/backend/domain/auth/jwt/SecurityContextProvider.java @@ -16,4 +16,8 @@ public static Long getAuthenticatedUserId() { } return (Long) principal; } + + public static Boolean isAuthenticated() { + return Objects.nonNull(SecurityContextHolder.getContext().getAuthentication()); + } } diff --git a/src/main/java/com/meetup/teame/backend/domain/user/service/UserService.java b/src/main/java/com/meetup/teame/backend/domain/user/service/UserService.java index 258f7c8..19072b1 100644 --- a/src/main/java/com/meetup/teame/backend/domain/user/service/UserService.java +++ b/src/main/java/com/meetup/teame/backend/domain/user/service/UserService.java @@ -47,7 +47,9 @@ public class UserService { private final ActivityLikeRepository activityLikeRepository; public ReadMainRes readMainPage() { - Long userId = SecurityContextProvider.getAuthenticatedUserId(); + Long userId = 5L; + if (SecurityContextProvider.isAuthenticated()) + userId = SecurityContextProvider.getAuthenticatedUserId(); User user = userRepository.findById(userId) .orElseThrow(() -> new CustomException(ExceptionContent.NOT_FOUND_USER)); return ReadMainRes.of(