Skip to content

Commit

Permalink
✅ 유저 조회 토큰 수정
Browse files Browse the repository at this point in the history
  • Loading branch information
tjdals4716 committed Aug 4, 2024
1 parent d32d5f9 commit d4a5e33
Showing 1 changed file with 5 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -61,10 +61,9 @@ public UserDTO createUser(UserDTO userDTO) {
//uid로 회원 조회
@Override
public UserDTO getUserByUid(String uid, UserDetails userDetails) {
if (!userDetails.getUsername().equals(uid)) {
throw new RuntimeException("권한이 없습니다.");
if (userDetails == null) {
throw new RuntimeException("인증되지 않은 유저입니다.");
}

UserEntity userEntity = userRepository.findByUid(uid)
.orElseThrow(() -> new RuntimeException("유저의 uid가 " + uid + "인 사용자를 찾을 수 없습니다"));
return UserDTO.entityToDto(userEntity);
Expand All @@ -73,13 +72,13 @@ public UserDTO getUserByUid(String uid, UserDetails userDetails) {
//닉네임으로 유저 조회
@Override
public UserDTO getUserByNickname(String nickname, UserDetails userDetails) {
if (userDetails == null) {
throw new RuntimeException("인증되지 않은 유저입니다.");
}
UserEntity userEntity = userRepository.findByNickname(nickname);
if (userEntity == null) {
throw new RuntimeException("유저의 nickname이 " + nickname + "인 사용자를 찾을 수 없습니다");
}
if (!userEntity.getUid().equals(userDetails.getUsername())) {
throw new RuntimeException("권한이 없습니다.");
}
return UserDTO.entityToDto(userEntity);
}

Expand Down

0 comments on commit d4a5e33

Please sign in to comment.