[회원 로그인 응답 개선] LoginResponseDto에 name 필드 추가 및 MemberMapper에 toLoginResponseDto 메서드 추가. JwtTokenIssuanceFilter에서 로그인 성공 시 LoginResponseDto 변환 로직 수정.

This commit is contained in:
2025-08-28 16:00:54 +09:00
parent fa1df19f64
commit a0ffeb236e
4 changed files with 14 additions and 6 deletions

View File

@@ -14,5 +14,6 @@ import java.time.LocalDateTime;
public class LoginResponseDto {
private String userId;
private String name;
private LocalDateTime lastLoginAt;
}

View File

@@ -2,13 +2,13 @@ package com.bio.bio_backend.domain.base.member.mapper;
import com.bio.bio_backend.domain.base.member.dto.CreateMemberRequestDto;
import com.bio.bio_backend.domain.base.member.dto.CreateMemberResponseDto;
import com.bio.bio_backend.domain.base.member.dto.LoginResponseDto;
import com.bio.bio_backend.domain.base.member.dto.MemberDto;
import com.bio.bio_backend.domain.base.member.entity.Member;
import com.bio.bio_backend.global.annotation.IgnoreBaseEntityMapping;
import com.bio.bio_backend.global.config.GlobalMapperConfig;
import org.mapstruct.Mapper;
import org.mapstruct.Mapping;
import org.mapstruct.factory.Mappers;
import java.util.List;
@Mapper(config = GlobalMapperConfig.class)
@@ -52,4 +52,9 @@ public interface MemberMapper {
*/
@IgnoreBaseEntityMapping
void updateMemberFromDto(MemberDto memberDto, @org.mapstruct.MappingTarget Member member);
/**
* MemberDto를 LoginResponseDto로 변환
*/
LoginResponseDto toLoginResponseDto(MemberDto memberDto);
}

View File

@@ -9,6 +9,7 @@ import com.bio.bio_backend.global.dto.ApiResponseDto;
import com.bio.bio_backend.domain.base.member.dto.LoginRequestDto;
import com.bio.bio_backend.domain.base.member.dto.LoginResponseDto;
import com.bio.bio_backend.domain.base.member.dto.MemberDto;
import com.bio.bio_backend.domain.base.member.mapper.MemberMapper;
import com.bio.bio_backend.domain.base.member.service.MemberService;
import com.bio.bio_backend.global.constants.ApiResponseCode;
import com.bio.bio_backend.global.utils.JwtUtils;
@@ -40,6 +41,7 @@ public class JwtTokenIssuanceFilter extends UsernamePasswordAuthenticationFilter
private final ObjectMapper objectMapper;
private final MemberService memberService;
private final HttpUtils httpUtils;
private final MemberMapper memberMapper;
// 사용자 login 인증 처리
@Override
@@ -83,16 +85,14 @@ public class JwtTokenIssuanceFilter extends UsernamePasswordAuthenticationFilter
context.setAuthentication(authResult);
contextHolder.setContext(context);
LoginResponseDto memberData = new LoginResponseDto();
memberData.setUserId(member.getUserId());
memberData.setLastLoginAt(member.getLastLoginAt());
LoginResponseDto loginResponseDto = memberMapper.toLoginResponseDto(member);
// login 성공 메시지 전송
response.setStatus(HttpStatus.OK.value());
response.setContentType(MediaType.APPLICATION_JSON_VALUE + ";charset=UTF-8");
objectMapper.writeValue(
response.getWriter(),
ApiResponseDto.success(ApiResponseCode.LOGIN_SUCCESSFUL, memberData)
ApiResponseDto.success(ApiResponseCode.LOGIN_SUCCESSFUL, loginResponseDto)
);
}
}

View File

@@ -19,6 +19,7 @@ import com.fasterxml.jackson.databind.ObjectMapper;
import com.bio.bio_backend.domain.base.member.service.MemberService;
import com.bio.bio_backend.domain.base.member.mapper.MemberMapper;
import com.bio.bio_backend.global.exception.CustomAuthenticationFailureHandler;
import com.bio.bio_backend.global.utils.JwtUtils;
import com.bio.bio_backend.global.utils.HttpUtils;
@@ -37,9 +38,10 @@ public class WebSecurity {
private final Environment env;
private final SecurityPathConfig securityPathConfig;
private final HttpUtils httpUtils;
private final MemberMapper memberMapper;
private JwtTokenIssuanceFilter getJwtTokenIssuanceFilter(AuthenticationManager authenticationManager) throws Exception {
JwtTokenIssuanceFilter filter = new JwtTokenIssuanceFilter(authenticationManager, jwtUtils, objectMapper, memberService, httpUtils);
JwtTokenIssuanceFilter filter = new JwtTokenIssuanceFilter(authenticationManager, jwtUtils, objectMapper, memberService, httpUtils, memberMapper);
filter.setFilterProcessesUrl("/login");
filter.setAuthenticationFailureHandler(new CustomAuthenticationFailureHandler(objectMapper));
return filter;