Skip to content

Commit

Permalink
Merge pull request #152 from farmingsoon/develop
Browse files Browse the repository at this point in the history
배포를 위한 Main merge
  • Loading branch information
gkfktkrh153 authored Mar 21, 2024
2 parents 1147c2e + 6a17e09 commit df95119
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import com.api.farmingsoon.common.security.jwt.JwtToken;
import com.api.farmingsoon.common.util.CookieUtils;
import com.api.farmingsoon.common.util.JwtUtils;
import com.api.farmingsoon.domain.member.dto.LoginResponse;
import com.api.farmingsoon.domain.member.model.Member;
import com.api.farmingsoon.domain.member.model.MemberRole;
import com.api.farmingsoon.domain.member.repository.MemberRepository;
Expand Down Expand Up @@ -37,27 +38,25 @@ public void onAuthenticationSuccess(HttpServletRequest request, HttpServletRespo
OAuth2User oAuth2User = (OAuth2User) authentication.getPrincipal();

String email = oAuth2User.getAttribute("email");
Optional<Member> findMember = memberRepository.findByEmail(email);

String name = oAuth2User.getAttribute("name");
String picture = oAuth2User.getAttribute("picture");
String provider = oAuth2User.getAttribute("provider");

Optional<Member> findMember = memberRepository.findByEmail(email + "_" + provider);

// 회원이 아닌 경우에 회원 가입 진행
Member member = null;
if (findMember.isEmpty()) {
member = Member.builder()
.email(email)
.email(email + "_" + provider)
.nickname(name)
.role(MemberRole.MEMBER)
.profileImg(picture)
.build();

memberRepository.save(member);
} else {
member = findMember.orElseThrow(() -> new NotFoundException(ErrorCode.NOT_FOUND_MEMBER));
member.updateSocialMember(email, name, picture);

memberRepository.save(member);
member = findMember.get();
}

// OAuth2User 객체에서 권한 가져옴
Expand All @@ -70,7 +69,7 @@ public void onAuthenticationSuccess(HttpServletRequest request, HttpServletRespo
response.setStatus(200);

response.getWriter().write(
objectMapper.writeValueAsString(jwtToken)
objectMapper.writeValueAsString(LoginResponse.of(member))
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
public class ChattingConnectResponse {

private Long connectMemberId;
private final String type = "SEND";
private final String type = "CONNECT";

public ChattingConnectResponse(Long connectMemberId) {
this.connectMemberId = connectMemberId;
Expand Down

0 comments on commit df95119

Please sign in to comment.