diff --git a/src/main/java/com/bio/bio_backend/domain/base/member/dto/LoginResponseDto.java b/src/main/java/com/bio/bio_backend/domain/base/member/dto/LoginResponseDto.java index 22d4068..0bfb95e 100644 --- a/src/main/java/com/bio/bio_backend/domain/base/member/dto/LoginResponseDto.java +++ b/src/main/java/com/bio/bio_backend/domain/base/member/dto/LoginResponseDto.java @@ -14,5 +14,6 @@ import java.time.LocalDateTime; public class LoginResponseDto { private String userId; + private String name; private LocalDateTime lastLoginAt; } diff --git a/src/main/java/com/bio/bio_backend/domain/base/member/mapper/MemberMapper.java b/src/main/java/com/bio/bio_backend/domain/base/member/mapper/MemberMapper.java index 779c323..886ec32 100644 --- a/src/main/java/com/bio/bio_backend/domain/base/member/mapper/MemberMapper.java +++ b/src/main/java/com/bio/bio_backend/domain/base/member/mapper/MemberMapper.java @@ -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); } diff --git a/src/main/java/com/bio/bio_backend/global/filter/JwtTokenIssuanceFilter.java b/src/main/java/com/bio/bio_backend/global/filter/JwtTokenIssuanceFilter.java index 7c5d12d..1b0efd8 100644 --- a/src/main/java/com/bio/bio_backend/global/filter/JwtTokenIssuanceFilter.java +++ b/src/main/java/com/bio/bio_backend/global/filter/JwtTokenIssuanceFilter.java @@ -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) ); } } diff --git a/src/main/java/com/bio/bio_backend/global/security/WebSecurity.java b/src/main/java/com/bio/bio_backend/global/security/WebSecurity.java index 88094bc..b209f47 100644 --- a/src/main/java/com/bio/bio_backend/global/security/WebSecurity.java +++ b/src/main/java/com/bio/bio_backend/global/security/WebSecurity.java @@ -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;