Skip to content

Commit

Permalink
feat: 로그인시 반환 정보 추가
Browse files Browse the repository at this point in the history
  • Loading branch information
EUNCHAEv1006 committed Jan 16, 2024
1 parent 4b1c581 commit 37ec560
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -33,15 +33,16 @@ public ResponseEntity<CommonResponse<Void>> signup(
}

@PostMapping("/login")
public ResponseEntity<CommonResponse<Void>> login(
public ResponseEntity<CommonResponse<UserInfoResponseDTO>> login(
@RequestBody UserLoginRequestDTO requestDTO, HttpServletResponse response) {

userService.login(requestDTO);
UserInfoResponseDTO userInfo = userService.login(requestDTO);

String token = jwtUtil.createToken(requestDTO.getUsername());
response.setHeader(JwtUtil.AUTHORIZATION_HEADER, token);

return ResponseEntity.ok()
.body(CommonResponse.of(HttpStatus.OK.value(), "로그인 성공", null));
.body(CommonResponse.of(HttpStatus.OK.value(), "로그인 성공", userInfo));
}

@GetMapping("/{userId}")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,13 @@
@AllArgsConstructor
public class UserInfoResponseDTO {

private Long userId;
private String username;
private String email;
private String description;

public UserInfoResponseDTO(User user) {
this.userId = user.getId();
this.username = user.getUsername();
this.email = user.getEmail();
this.description = user.getDescription();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public void signup(UserSignupRequestDTO requestDTO) {
userRepository.save(user);
}

public void login(UserLoginRequestDTO requestDTO) {
public UserInfoResponseDTO login(UserLoginRequestDTO requestDTO) {
String username = requestDTO.getUsername();
String password = requestDTO.getPassword();

Expand All @@ -62,6 +62,9 @@ public void login(UserLoginRequestDTO requestDTO) {
if (!passwordEncoder.matches(password, user.getPassword())) {
throw new UserNotFoundException();
}

// 로그인 성공시 UserInfoResponseDTO로 변환하여 반환
return new UserInfoResponseDTO(user);
}

public UserInfoResponseDTO getProfile(Long user_id) {
Expand Down

0 comments on commit 37ec560

Please sign in to comment.