Skip to content

Commit d23311d

Browse files
committed
BugFix: 충돌 해결
1 parent aa954e8 commit d23311d

File tree

5 files changed

+22
-16
lines changed

5 files changed

+22
-16
lines changed

backend/src/main/java/com/together/backend/domain/user/repository/UserRepository.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,5 @@
77

88
public interface UserRepository extends JpaRepository<User, Long> {
99
Optional<User> findByEmail(String email);
10+
Optional<User> findByUserId(Long userId);
1011
}

backend/src/main/java/com/together/backend/global/common/BaseResponse.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,9 @@ public class BaseResponse<T> {
2020

2121
// 요청에 성공한 경우
2222
public BaseResponse(T result) {
23-
this.isSuccess = BaseResponseStatus.SUCCESS.isSuccess();
24-
this.status = BaseResponseStatus.SUCCESS.getCode();
25-
this.message = BaseResponseStatus.SUCCESS.getMessage();
23+
this.isSuccess = BaseResponseStatus.OK.isSuccess();
24+
this.status = BaseResponseStatus.OK.getCode();
25+
this.message = BaseResponseStatus.OK.getMessage();
2626
this.result = result;
2727
}
2828

backend/src/main/java/com/together/backend/global/security/jwt/JWTFilter.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
package com.together.backend.global.security.jwt;
22

33

4+
import com.together.backend.global.security.jwt.model.BlackListToken;
5+
import com.together.backend.global.security.jwt.service.BlackListTokenService;
46
import com.together.backend.global.security.jwt.util.CookieUtil;
57
import com.together.backend.global.security.jwt.util.JWTUtil;
68
import com.together.backend.global.security.oauth2.dto.CustomOAuth2User;
@@ -24,6 +26,7 @@
2426
public class JWTFilter extends OncePerRequestFilter {
2527

2628
private final JWTUtil jwtUtil;
29+
private final BlackListTokenService blackListTokenService;
2730

2831
@Override
2932
protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response, FilterChain filterChain)

backend/src/main/java/com/together/backend/global/security/jwt/util/CookieUtil.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,10 @@ public static void createCookie(HttpServletResponse response, String name, Strin
3636
response.addCookie(cookie); // 쿠키를 응답에 추가
3737
}
3838

39-
public static Cookie deleteCookie(String name) {
39+
public static Cookie deleteCookie(String name, String path) {
4040
Cookie cookie = new Cookie(name, null);
4141
cookie.setMaxAge(0); // 쿠키 즉시 만료
42-
cookie.setPath("/"); // 쿠키 경로 설정
42+
cookie.setPath(path); // 쿠키 경로 설정
4343
cookie.setHttpOnly(true);
4444
return cookie; // 삭제할 쿠키 반환
4545
}

backend/src/main/java/com/together/backend/global/security/oauth2/CustomOAuth2UserService.java

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414
import org.springframework.security.oauth2.core.user.OAuth2User;
1515
import org.springframework.stereotype.Service;
1616

17+
import java.util.Optional;
18+
1719

1820
@Slf4j
1921
@RequiredArgsConstructor
@@ -33,10 +35,10 @@ public OAuth2User loadUser(OAuth2UserRequest userRequest) throws OAuth2Authentic
3335

3436

3537

36-
User existData = userRepository.findByEmail(kakaoResponse.getEmail()); // 이메일로 사용자 조회
38+
Optional<User> existData = userRepository.findByEmail(kakaoResponse.getEmail()); // 이메일로 사용자 조회
3739

3840
// 신규 회원일 때
39-
if (existData == null) {
41+
if (existData.isEmpty()) {
4042
User user = new User();
4143
user.setSocialId(kakaoResponse.getSocialId());
4244
user.setNickname(kakaoResponse.getName());
@@ -56,24 +58,24 @@ public OAuth2User loadUser(OAuth2UserRequest userRequest) throws OAuth2Authentic
5658
}
5759
// 기존 회원일 때
5860
else {
59-
61+
User user = existData.get();
6062
// 이메일 또는 닉네임이 변경되었는지 확인
61-
if (!existData.getNickname().equals(kakaoResponse.getName())||
62-
!existData.getEmail().equals(kakaoResponse.getEmail()) ||
63-
!existData.getProfileImageUrl().equals(kakaoResponse.getProfileImageUrl())) {
63+
if (!user.getNickname().equals(kakaoResponse.getName())||
64+
!user.getEmail().equals(kakaoResponse.getEmail()) ||
65+
!user.getProfileImageUrl().equals(kakaoResponse.getProfileImageUrl())) {
6466
log.info("기존 사용자 정보 업데이트: 이메일 또는 닉네임 변경");
65-
existData.setEmail(kakaoResponse.getEmail());
66-
existData.setNickname(kakaoResponse.getName());
67-
existData.setProfileImageUrl(kakaoResponse.getProfileImageUrl());
68-
userRepository.save(existData); // 변경된 내용 저장
67+
user.setEmail(kakaoResponse.getEmail());
68+
user.setNickname(kakaoResponse.getName());
69+
user.setProfileImageUrl(kakaoResponse.getProfileImageUrl());
70+
userRepository.save(user); // 변경된 내용 저장
6971
}
7072

7173
UserDTO userDTO = UserDTO.builder()
7274
.socialId(kakaoResponse.getSocialId())
7375
.name(kakaoResponse.getName())
7476
.email(kakaoResponse.getEmail())
7577
.profileImageUrl(kakaoResponse.getProfileImageUrl())
76-
.role(existData.getRole())
78+
.role(user.getRole())
7779
.build();
7880
return new CustomOAuth2User(userDTO);
7981
}

0 commit comments

Comments
 (0)