From cff0382aef909d22b8bfc5ec17d4dbfe5105f42e Mon Sep 17 00:00:00 2001 From: HyunSu1768 Date: Sat, 30 Mar 2024 15:58:07 +0900 Subject: [PATCH] =?UTF-8?q?BUG=20::=20=EB=B2=84=EA=B7=B8=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../domain/auth/service/LoginService.kt | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/src/main/kotlin/xquare/app/xquareinfra/domain/auth/service/LoginService.kt b/src/main/kotlin/xquare/app/xquareinfra/domain/auth/service/LoginService.kt index 464fd56..67aef6b 100644 --- a/src/main/kotlin/xquare/app/xquareinfra/domain/auth/service/LoginService.kt +++ b/src/main/kotlin/xquare/app/xquareinfra/domain/auth/service/LoginService.kt @@ -1,5 +1,6 @@ package xquare.app.xquareinfra.domain.auth.service +import kotlinx.serialization.json.Json import org.springframework.stereotype.Service import org.springframework.transaction.annotation.Transactional import xquare.app.xquareinfra.domain.auth.adapter.dto.request.LoginRequest @@ -11,7 +12,9 @@ import xquare.app.xquareinfra.domain.user.application.port.out.SaveUserPort import xquare.app.xquareinfra.domain.user.domain.Role import xquare.app.xquareinfra.domain.user.domain.User import xquare.app.xquareinfra.infrastructure.exception.BusinessLogicException +import xquare.app.xquareinfra.infrastructure.exception.XquareException import xquare.app.xquareinfra.infrastructure.feign.client.dsm.DsmLoginClient +import xquare.app.xquareinfra.infrastructure.feign.client.dsm.dto.GetDsmUserInfoResponse @Transactional @Service @@ -21,12 +24,17 @@ class LoginService( private val generateJwtPort: GenerateJwtPort ): LoginUseCase { override fun login(loginRequest: LoginRequest): TokenResponse { - val user = findUserPort.findByAccountId(loginRequest.accountId) ?: throw BusinessLogicException.USER_NOT_FOUND - dsmLoginClient.getUserInfo( + val feignResponse = dsmLoginClient.getUserInfo( accountId = loginRequest.accountId, password = loginRequest.password ) - val tokenPair = generateJwtPort.generateTokens(user.id.toString()) + + if(feignResponse.status() >= 400) { + throw XquareException.UNAUTHORIZED + } + + val userInfo = Json.decodeFromString(feignResponse.body().toString()) + val tokenPair = generateJwtPort.generateTokens(userInfo.id) return TokenResponse( accessToken = tokenPair.first, refreshToken = tokenPair.second