Skip to content

Commit

Permalink
BUG :: 버그수정
Browse files Browse the repository at this point in the history
  • Loading branch information
HyunSu1768 committed Mar 30, 2024
1 parent 6cf809e commit cff0382
Showing 1 changed file with 11 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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
Expand All @@ -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<GetDsmUserInfoResponse>(feignResponse.body().toString())
val tokenPair = generateJwtPort.generateTokens(userInfo.id)
return TokenResponse(
accessToken = tokenPair.first,
refreshToken = tokenPair.second
Expand Down

0 comments on commit cff0382

Please sign in to comment.