From 808996922810f7d52c0f29f399e74f2ce704c272 Mon Sep 17 00:00:00 2001 From: yskim6772 Date: Wed, 15 Oct 2025 15:39:40 +0900 Subject: [PATCH] =?UTF-8?q?[Hotfix]=20#19=20getCurrentUser=20=ED=95=A8?= =?UTF-8?q?=EC=88=98=20=EB=A1=9C=EC=A7=81=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../WhoIs_Server/domain/club/service/ClubService.java | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/WhoIsRoom/WhoIs_Server/domain/club/service/ClubService.java b/src/main/java/com/WhoIsRoom/WhoIs_Server/domain/club/service/ClubService.java index f4efbac..28f632e 100644 --- a/src/main/java/com/WhoIsRoom/WhoIs_Server/domain/club/service/ClubService.java +++ b/src/main/java/com/WhoIsRoom/WhoIs_Server/domain/club/service/ClubService.java @@ -1,5 +1,6 @@ package com.WhoIsRoom.WhoIs_Server.domain.club.service; +import com.WhoIsRoom.WhoIs_Server.domain.auth.model.UserPrincipal; import com.WhoIsRoom.WhoIs_Server.domain.club.dto.response.ClubPresenceResponse; import com.WhoIsRoom.WhoIs_Server.domain.club.dto.response.ClubResponse; import com.WhoIsRoom.WhoIs_Server.domain.club.dto.response.MyClubsResponse; @@ -14,6 +15,7 @@ import com.WhoIsRoom.WhoIs_Server.global.common.response.ErrorCode; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; +import org.springframework.security.core.Authentication; import org.springframework.security.core.context.SecurityContextHolder; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; @@ -63,8 +65,12 @@ public void checkOut(Long clubId) { } private User getCurrentUser() { - String nickname = SecurityContextHolder.getContext().getAuthentication().getName(); - return userRepository.findByNickName(nickname) + Authentication authentication = SecurityContextHolder.getContext().getAuthentication(); + if (authentication == null || !(authentication.getPrincipal() instanceof UserPrincipal principal)) { + throw new BusinessException(ErrorCode.USER_NOT_FOUND); + } + + return userRepository.findById(principal.getUserId()) .orElseThrow(() -> new BusinessException(ErrorCode.USER_NOT_FOUND)); }