Skip to content

Commit

Permalink
Merge pull request #172 from Soongsil-CoffeeChat/ref/#170
Browse files Browse the repository at this point in the history
FIX: Optional객체에 맞게 로직수정, 임포트 에러 해결(#170)
  • Loading branch information
KimKyoHwee authored Oct 22, 2024
2 parents 776fda7 + 49350a2 commit 4e458c1
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 43 deletions.
34 changes: 0 additions & 34 deletions src/main/java/com/soongsil/CoffeeChat/config/S3Config.java

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ protected void doFilterInternal(HttpServletRequest request, HttpServletResponse
return;
}
String path = request.getRequestURI();
if (path.startsWith("/health-check") || path.startsWith("/security-check") || path.startsWith("/auth/reissue")) {
if (path.startsWith("/health-check") || path.startsWith("/security-check") || path.startsWith("/auth/reissue")||path.startsWith("/login")) {
System.out.println("jwt필터 통과로직");
filterChain.doFilter(request, response);
return;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import java.util.Date;
import java.util.Iterator;

import com.soongsil.CoffeeChat.dto.Oauth.CustomOAuth2User;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseCookie;
import org.springframework.security.core.Authentication;
Expand All @@ -14,7 +15,7 @@
import org.springframework.stereotype.Component;

import com.soongsil.CoffeeChat.config.jwt.JWTUtil;
import com.soongsil.CoffeeChat.dto.Oauth.CustomOAuth2User;

import com.soongsil.CoffeeChat.entity.Refresh;
import com.soongsil.CoffeeChat.repository.RefreshRepository;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,4 @@ public interface UserRepository extends JpaRepository<User, Long>, UserRepositor

UserGetDto findUserInfoByUsername(String username);
}

Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import static com.soongsil.CoffeeChat.controller.exception.enums.RefreshErrorCode.*;

import java.util.Map;
import java.util.Optional;

import org.springframework.security.oauth2.client.userinfo.DefaultOAuth2UserService;
import org.springframework.security.oauth2.client.userinfo.OAuth2UserRequest;
Expand Down Expand Up @@ -38,6 +39,7 @@ public class CustomOAuth2UserService extends DefaultOAuth2UserService {
private static final String GOOGLE_TOKEN_INFO_URL = "https://www.googleapis.com/oauth2/v3/tokeninfo?access_token=";

private User findUserByUsername(String username) {
System.out.println("여기까지 들어옴");
return userRepository.findByUsername(username)
.orElse(null);
}
Expand Down Expand Up @@ -69,8 +71,9 @@ public OAuth2User loadUser(OAuth2UserRequest userRequest) throws OAuth2Authentic
String username = oAuth2Response.getProvider() + " " + oAuth2Response.getProviderId();

//유저가 DB에 있는지 확인 후 없으면 새로 저장
User existData = findUserByUsername(username);
if (existData == null) {
Optional<User> existData = userRepository.findByUsername(username);
//User existData = findUserByUsername(username);
if (existData.isEmpty()) {
User user = new User();
user.setUsername(username);
user.setEmail(oAuth2Response.getEmail());
Expand All @@ -87,14 +90,14 @@ public OAuth2User loadUser(OAuth2UserRequest userRequest) throws OAuth2Authentic
return new CustomOAuth2User(userDTO);
} else { //데이터가 이미 존재하면 업데이트 후 OAuth2User객체로 반환
//소셜에서 로그인마다 업데이트를 선호하므로 로그인마다 DB 업데이트 진행
existData.setEmail(oAuth2Response.getEmail());
existData.setName(oAuth2Response.getName());
userRepository.save(existData);
existData.get().setEmail(oAuth2Response.getEmail());
existData.get().setName(oAuth2Response.getName());
userRepository.save(existData.get());

UserDTO userDTO = new UserDTO();
userDTO.setUsername(existData.getUsername());
userDTO.setUsername(existData.get().getUsername());
userDTO.setName(oAuth2Response.getName());
userDTO.setRole(existData.getRole());
userDTO.setRole(existData.get().getRole());
return new CustomOAuth2User(userDTO);
}

Expand Down

0 comments on commit 4e458c1

Please sign in to comment.