Skip to content

[Sping MVC(인증)] 김예진 미션 제출합니다. #160

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: dpwls0125
Choose a base branch
from

Conversation

dPwls0125
Copy link

안녕하세요 오찌!
Spring 인증 미션 제출합니다.

이번 미션을 통해 ArgumentResolver, Interceptor의 동작 방식과 사용 방법에 대해 제대로 다루어볼 수 있어 즐거웠습니다.

Copy link

@Ohzzi Ohzzi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

수고 많으셨습니다 예진님. 전체적으로 리뷰는 비즈니스가 이뤄지는 영역의 구분과 위치에 대한 내용에 대한게 주를 이뤘습니다. 항상 정답은 없는 내용이지만, 이 부분을 생각해보는게 나중에 실무에 가서 정말 큰 도움이 되는 부분이라고 생각해요.

추가로 이번 미션을 하면서 어려웠거나 더 공부해보고 싶은 부분이 있었을까요? 말씀해주시면 해당 부분에 맞춰서 좀 더 깊은 리뷰를 들어가볼 수 있을 것 같아요!

Comment on lines +33 to +44
public LoginMember parseTokenAndGetMemberInfo(Cookie[] cookies) {

String token = "";
for (Cookie cookie : cookies) {
if (cookie.getName().equals("token"))
token = cookie.getValue();
}

if (token.isEmpty()) throw new IllegalArgumentException("로그인하지 않은 사용자입니다.");

return tokenParser.paseMemberInfo(token);
}
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

쿠키는 웹 기술의 영역이기 때문에 인터셉터에서 쿠키에서 원하는 값을 꺼내고 서비스에 전달해주는 형태로 구현해보는 것은 어떨까요? 지금은 너무 비즈니스 영역까지 들어온 느낌이에요. 토큰 값이 쿠키에 있든 리퀘스트바디로 넘어오든 MemberService 입장에서는 알 필요 없고 회원에 대한 책임만 가지면 되지 않을까요?

@Value("${roomescape.auth.jwt.secret}")
private String secretKey;

public LoginMember paseMemberInfo(String token) {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

오타 있네요!

Comment on lines +13 to +14
private final TokenProvider tokenProvider;
private final TokenParser tokenParser;
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

개인적으로는 아예 토큰 관련된 의존성은 전부 멤버서비스 바깥에 있는 쪽을 더 선호(멤버서비스는 정말 회원에 대한 의존만)하기는 합니다. 이 의존성 관련해서는 정답은 없으니 다각도로 고민해보세요!

return new ReservationResponse(reservation.getId(), reservationRequest.getName(), reservation.getTheme().getName(), reservation.getDate(), reservation.getTime().getValue());
}

private ReservationRequest replaceNameIfEmpty(ReservationRequest request, LoginMember loginMember) {
if (request.getName() == null || request.getName().isBlank()) {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

getName을 미리 변수로 꺼내놓으면 두 번 호출하지 않아도 되겠죠?

Comment on lines +3 to +14
public class LoginRequest {
private String email;
private String password;

public String getEmail() {
return email;
}

public String getPassword() {
return password;
}
}
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

record를 사용해봐도 좋을 것 같네요

private Long id;
private String name;
private String email;
private String role;
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

role은 enum인 것이 더 관리되기 쉽지 않을까요?

Comment on lines +27 to +47
@PostMapping("/login")
public ResponseEntity<Void> login(@RequestBody LoginRequest loginRequest) {
TokenResponse token = memberService.getAccessToken(loginRequest.getEmail(), loginRequest.getPassword());
ResponseCookie cookie = ResponseCookie.from("token", token.getAccessToken())
.httpOnly(true)
.path("/")
.build();

return ResponseEntity.ok()
.header(HttpHeaders.SET_COOKIE, cookie.toString())
.build();
}

@GetMapping("/login/check")
public ResponseEntity<MemberResponse> loingCheck(HttpServletRequest request) {
Cookie[] cookies = request.getCookies();
LoginMember loginMember = memberService.parseTokenAndGetMemberInfo(cookies);
MemberResponse response = new MemberResponse(loginMember.getId(), loginMember.getName(), loginMember.getEmail());
return ResponseEntity.ok().body(response);
}

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

로그인 관련해서는 컨트롤러가 별도로 분리되는게 좋을 것 같아요! 회원 컨트롤러는 회원 매니징에 대해서만 갖는게 맞고 로그인은 인증인가의 영역이니까요!

Comment on lines +27 to +29
.claim("name", member.getName())
.claim("role", member.getRole())
.claim("email", member.getEmail())
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

토큰에 너무 많은 정보가 들어가는 것 아닐까요?


public LoginMember parseTokenAndGetMemberInfo(Cookie[] cookies) {

String token = "";
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

토큰이 없는 것은 null이 더 명시적이지 않을까 하는 생각이 듭니다. 빈 문자열은 정말 빈 문자열과 헷갈릴 수 있잖아요? (물론 이 경우 빈 문자열도 문제가 되어야 하는 것은 마찬가지겠지만)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants