Skip to content

Commit

Permalink
Fix login error. (#213)
Browse files Browse the repository at this point in the history
* Fix login error.
* Fix login DB issue.

Signed-off-by: Han Kyuhyun <[email protected]>
Co-authored-by: ByunJeongHeum <[email protected]>
Co-authored-by: June Saehwan <[email protected]>
Co-authored-by: Jongmin Lee <[email protected]>
  • Loading branch information
4 people authored Sep 14, 2023
1 parent d7d8009 commit b818268
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 8 deletions.
3 changes: 1 addition & 2 deletions frontend/src/pages/Home.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ export const Home = () => {
}
}


return (
<div className="home">
<div className="div">
Expand Down Expand Up @@ -91,7 +90,7 @@ export const Home = () => {
{isLoggedIn ? (
<span style={{ color: "black", textDecoration: "none" }}>
<Link
to={"/user/info"}
to={"/home"}
style={{ color: "black", textDecoration: "none" }}
>
{username?.name ? (
Expand Down
3 changes: 0 additions & 3 deletions src/main/java/com/lpvs/auth/OAuthService.java
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@ public OAuth2User loadUser(OAuth2UserRequest userRequest) throws OAuth2Authentic
return new DefaultOAuth2User(Collections.singleton(new SimpleGrantedAuthority("USER")),
customAttribute,
userNameAttributeName);

}

private Map<String, Object> customAttribute(Map<String, Object> attributes, String userNameAttributeName, MemberProfile memberProfile, String registrationId) {
Expand All @@ -62,7 +61,6 @@ private Map<String, Object> customAttribute(Map<String, Object> attributes, Stri
customAttribute.put("name", memberProfile.getName());
customAttribute.put("email", memberProfile.getEmail());
return customAttribute;

}

private LPVSMember saveOrUpdate(MemberProfile memberProfile) {
Expand All @@ -73,5 +71,4 @@ private LPVSMember saveOrUpdate(MemberProfile memberProfile) {

return lpvsMemberRepository.save(lpvsMember);
}

}
6 changes: 6 additions & 0 deletions src/main/java/com/lpvs/entity/LPVSMember.java
Original file line number Diff line number Diff line change
Expand Up @@ -62,4 +62,10 @@ public void setNickname(String nickname) {
public void setOrganization(String organization) {
this.organization = organization;
}

public void setJoin(String name, String email, String provider) {
this.name = name;
this.email = email;
this.provider = provider;
}
}
16 changes: 13 additions & 3 deletions src/main/java/com/lpvs/service/LPVSLoginCheckService.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,10 @@
import org.springframework.security.core.Authentication;
import org.springframework.security.oauth2.core.user.OAuth2User;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

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

@Service
public class LPVSLoginCheckService {
Expand Down Expand Up @@ -44,14 +46,22 @@ public void loginVerification(Authentication authentication) {
}
}

@Transactional
public LPVSMember getMemberFromMemberMap(Authentication authentication) {
Map<String, Object> memberMap = getOauthLoginMemberMap(authentication);
String name = (String) memberMap.get("name");
String email = (String) memberMap.get("email");
String provider = (String) memberMap.get("provider");

LPVSMember findMember = memberRepository.findByEmailAndProvider(email, provider).get();
Optional<LPVSMember> findMemberOptional = memberRepository.findByEmailAndProvider(email, provider);

return findMember;
if (findMemberOptional.isPresent()) {
return findMemberOptional.get();
} else {
LPVSMember newMember = new LPVSMember();
newMember.setJoin(name, email, provider);
memberRepository.save(newMember);
return newMember;
}
}

}

0 comments on commit b818268

Please sign in to comment.