Skip to content

Commit a2c4fd6

Browse files
authored
Merge pull request #20 from WhosInRoom/hotfix/#19-user-not-found-error
[Hotfix] 닉네임 수정 후 사용자 존재 오류 해결
2 parents b670a6a + 8089969 commit a2c4fd6

1 file changed

Lines changed: 8 additions & 2 deletions

File tree

src/main/java/com/WhoIsRoom/WhoIs_Server/domain/club/service/ClubService.java

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package com.WhoIsRoom.WhoIs_Server.domain.club.service;
22

3+
import com.WhoIsRoom.WhoIs_Server.domain.auth.model.UserPrincipal;
34
import com.WhoIsRoom.WhoIs_Server.domain.club.dto.response.ClubPresenceResponse;
45
import com.WhoIsRoom.WhoIs_Server.domain.club.dto.response.ClubResponse;
56
import com.WhoIsRoom.WhoIs_Server.domain.club.dto.response.MyClubsResponse;
@@ -14,6 +15,7 @@
1415
import com.WhoIsRoom.WhoIs_Server.global.common.response.ErrorCode;
1516
import lombok.RequiredArgsConstructor;
1617
import lombok.extern.slf4j.Slf4j;
18+
import org.springframework.security.core.Authentication;
1719
import org.springframework.security.core.context.SecurityContextHolder;
1820
import org.springframework.stereotype.Service;
1921
import org.springframework.transaction.annotation.Transactional;
@@ -63,8 +65,12 @@ public void checkOut(Long clubId) {
6365
}
6466

6567
private User getCurrentUser() {
66-
String nickname = SecurityContextHolder.getContext().getAuthentication().getName();
67-
return userRepository.findByNickName(nickname)
68+
Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
69+
if (authentication == null || !(authentication.getPrincipal() instanceof UserPrincipal principal)) {
70+
throw new BusinessException(ErrorCode.USER_NOT_FOUND);
71+
}
72+
73+
return userRepository.findById(principal.getUserId())
6874
.orElseThrow(() -> new BusinessException(ErrorCode.USER_NOT_FOUND));
6975
}
7076

0 commit comments

Comments
 (0)