Skip to content

Commit

Permalink
refactor: MemberDto 수정
Browse files Browse the repository at this point in the history
  • Loading branch information
pjm2571 committed Oct 22, 2024
1 parent fe26773 commit 033c049
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 16 deletions.
6 changes: 1 addition & 5 deletions BE/Blog/src/main/java/hyundai/blog/member/dto/MemberDto.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,16 +23,12 @@ public class MemberDto extends User {
// JWT Claims로부터 MemberDto 생성
public MemberDto(Map<String, Object> claims) {
super((String) claims.get("email"), "", mapToGrantedAuthorities((String) claims.get("role")));

String roleString = (String) claims.get("role");
MemberRole role = MemberRole.valueOf(roleString); // String을 Enum으로 변환

this.email = (String) claims.get("email");
this.name = (String) claims.get("name");
this.profileImage = (String) claims.get("profileImage");
this.nickname = (String) claims.get("name"); // JWT에서 별도의 닉네임 필드가 없으므로 name을 사용
this.social = (String) claims.get("social");
this.memberRoleList = List.of(role); // MemberRole 리스트로 저장
this.memberRoleList = List.of(MemberRole.valueOf((String) claims.get("role")));
}

// role을 GrantedAuthority로 변환하는 메소드
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,16 +51,6 @@ public void onAuthenticationSuccess(HttpServletRequest request, HttpServletRespo
"role", userInfo.role()
);

MemberDto memberDto = new MemberDto(claims);

// 인증 토큰 생성 및 SecurityContext 설정
UsernamePasswordAuthenticationToken authenticationToken = new UsernamePasswordAuthenticationToken(
memberDto, "", memberDto.getAuthorities());

SecurityContextHolder.getContext().setAuthentication(authenticationToken);

log.info("유저 액세스 성공 userName : {}", memberDto.getUsername());

String accessToken = jwtTokenProvider.generateAccessToken(claims);
String refreshToken = jwtTokenProvider.createRefreshToken();

Expand All @@ -82,7 +72,7 @@ public void onAuthenticationSuccess(HttpServletRequest request, HttpServletRespo
response.addCookie(refreshTokenCookie);


// 7. application.yaml에서 주입받은 redirectUrl 사용
// 6. application.yaml에서 주입받은 redirectUrl 사용
response.sendRedirect(redirectUrl);
}
}

0 comments on commit 033c049

Please sign in to comment.