From de9d3562016a15490e26bcb6517d59064fce172a Mon Sep 17 00:00:00 2001 From: yeonjy Date: Mon, 17 Jun 2024 18:27:55 +0900 Subject: [PATCH] =?UTF-8?q?fix:=20user=20=EC=A0=95=EB=B3=B4=20=EB=AA=A8?= =?UTF-8?q?=EB=91=90=20=EB=B0=9B=EA=B8=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../backend/global/oauth2/OAuthAttributes.java | 2 +- .../backend/global/oauth2/service/AuthService.java | 9 ++++----- 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/backend/core/src/main/java/com/rollthedice/backend/global/oauth2/OAuthAttributes.java b/backend/core/src/main/java/com/rollthedice/backend/global/oauth2/OAuthAttributes.java index f3aacaa1..2dfcb75c 100644 --- a/backend/core/src/main/java/com/rollthedice/backend/global/oauth2/OAuthAttributes.java +++ b/backend/core/src/main/java/com/rollthedice/backend/global/oauth2/OAuthAttributes.java @@ -41,7 +41,7 @@ public Member toEntity(SocialType socialType, OAuth2UserInfo oauth2UserInfo) { .email(oauth2UserInfo.getEmail()) .nickname(oauth2UserInfo.getNickname()) .imageUrl(oauth2UserInfo.getImageUrl()) - .role(Role.GUEST) + .role(Role.USER) .status(Status.ACTIVE) .build(); } diff --git a/backend/core/src/main/java/com/rollthedice/backend/global/oauth2/service/AuthService.java b/backend/core/src/main/java/com/rollthedice/backend/global/oauth2/service/AuthService.java index 3d150356..85bcaef7 100644 --- a/backend/core/src/main/java/com/rollthedice/backend/global/oauth2/service/AuthService.java +++ b/backend/core/src/main/java/com/rollthedice/backend/global/oauth2/service/AuthService.java @@ -41,8 +41,8 @@ private Member registerMember(SocialType socialType, OAuth2UserInfo userInfo) { Member member = Member.builder() .socialType(socialType) .oauthId(userInfo.getId()) - .email(UUID.randomUUID() + "@socialUser.com") - .nickname(String.valueOf(UUID.randomUUID())) + .email(userInfo.getEmail()) + .nickname(userInfo.getNickname()) .imageUrl(userInfo.getImageUrl()) .role(Role.USER) .build(); @@ -51,10 +51,9 @@ private Member registerMember(SocialType socialType, OAuth2UserInfo userInfo) { } public Member getMember() { - Authentication authentication = SecurityContextHolder.getContext().getAuthentication(); - UserDetails userDetails = (UserDetails) authentication.getPrincipal(); - return memberRepository.findByEmail(userDetails.getUsername()).orElseThrow(MemberNotFoundException::new); + String username = authentication.getName(); + return memberRepository.findByEmail(username).orElseThrow(MemberNotFoundException::new); } }