[회원 로그인 응답 개선] 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 { public class LoginResponseDto {
private String userId; private String userId;
private String name;
private LocalDateTime lastLoginAt; 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.CreateMemberRequestDto;
import com.bio.bio_backend.domain.base.member.dto.CreateMemberResponseDto; 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.dto.MemberDto;
import com.bio.bio_backend.domain.base.member.entity.Member; import com.bio.bio_backend.domain.base.member.entity.Member;
import com.bio.bio_backend.global.annotation.IgnoreBaseEntityMapping; import com.bio.bio_backend.global.annotation.IgnoreBaseEntityMapping;
import com.bio.bio_backend.global.config.GlobalMapperConfig; import com.bio.bio_backend.global.config.GlobalMapperConfig;
import org.mapstruct.Mapper; import org.mapstruct.Mapper;
import org.mapstruct.Mapping; import org.mapstruct.Mapping;
import org.mapstruct.factory.Mappers;
import java.util.List; import java.util.List;
@Mapper(config = GlobalMapperConfig.class) @Mapper(config = GlobalMapperConfig.class)
@@ -52,4 +52,9 @@ public interface MemberMapper {
*/ */
@IgnoreBaseEntityMapping @IgnoreBaseEntityMapping
void updateMemberFromDto(MemberDto memberDto, @org.mapstruct.MappingTarget Member member); 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.LoginRequestDto;
import com.bio.bio_backend.domain.base.member.dto.LoginResponseDto; 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.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.domain.base.member.service.MemberService;
import com.bio.bio_backend.global.constants.ApiResponseCode; import com.bio.bio_backend.global.constants.ApiResponseCode;
import com.bio.bio_backend.global.utils.JwtUtils; import com.bio.bio_backend.global.utils.JwtUtils;
@@ -40,6 +41,7 @@ public class JwtTokenIssuanceFilter extends UsernamePasswordAuthenticationFilter
private final ObjectMapper objectMapper; private final ObjectMapper objectMapper;
private final MemberService memberService; private final MemberService memberService;
private final HttpUtils httpUtils; private final HttpUtils httpUtils;
private final MemberMapper memberMapper;
// 사용자 login 인증 처리 // 사용자 login 인증 처리
@Override @Override
@@ -83,16 +85,14 @@ public class JwtTokenIssuanceFilter extends UsernamePasswordAuthenticationFilter
context.setAuthentication(authResult); context.setAuthentication(authResult);
contextHolder.setContext(context); contextHolder.setContext(context);
LoginResponseDto memberData = new LoginResponseDto(); LoginResponseDto loginResponseDto = memberMapper.toLoginResponseDto(member);
memberData.setUserId(member.getUserId());
memberData.setLastLoginAt(member.getLastLoginAt());
// login 성공 메시지 전송 // login 성공 메시지 전송
response.setStatus(HttpStatus.OK.value()); response.setStatus(HttpStatus.OK.value());
response.setContentType(MediaType.APPLICATION_JSON_VALUE + ";charset=UTF-8"); response.setContentType(MediaType.APPLICATION_JSON_VALUE + ";charset=UTF-8");
objectMapper.writeValue( objectMapper.writeValue(
response.getWriter(), 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.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.exception.CustomAuthenticationFailureHandler;
import com.bio.bio_backend.global.utils.JwtUtils; import com.bio.bio_backend.global.utils.JwtUtils;
import com.bio.bio_backend.global.utils.HttpUtils; import com.bio.bio_backend.global.utils.HttpUtils;
@@ -37,9 +38,10 @@ public class WebSecurity {
private final Environment env; private final Environment env;
private final SecurityPathConfig securityPathConfig; private final SecurityPathConfig securityPathConfig;
private final HttpUtils httpUtils; private final HttpUtils httpUtils;
private final MemberMapper memberMapper;
private JwtTokenIssuanceFilter getJwtTokenIssuanceFilter(AuthenticationManager authenticationManager) throws Exception { 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.setFilterProcessesUrl("/login");
filter.setAuthenticationFailureHandler(new CustomAuthenticationFailureHandler(objectMapper)); filter.setAuthenticationFailureHandler(new CustomAuthenticationFailureHandler(objectMapper));
return filter; return filter;