Skip to content

Commit

Permalink
feat/#71: getUserInfo() - 토큰 만료 시 빈 User 객체를 내려주게 설정
Browse files Browse the repository at this point in the history
  • Loading branch information
jinukeu committed Dec 27, 2023
1 parent 64af04f commit 21ccda8
Showing 1 changed file with 16 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import com.suwiki.domain.user.repository.UserRepository
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.first
import kotlinx.coroutines.flow.flow
import kotlinx.coroutines.flow.zip
import javax.inject.Inject

class UserRepositoryImpl @Inject constructor(
Expand Down Expand Up @@ -39,8 +40,22 @@ class UserRepositoryImpl @Inject constructor(
emit(localUserInfo)

val remoteUserInfo = remoteUserDataSource.getUserInfo()
emit(remoteUserInfo)

val isTokenExpired = with(securityPreferences) {
val (accessToken, refreshToken) = flowAccessToken().zip(flowRefreshToken()) { accessToken, refreshToken ->
(accessToken to refreshToken)
}.first()

accessToken.isEmpty() && refreshToken.isEmpty()
}

if (isTokenExpired) {
logout()
emit(User())
return@flow
}

emit(remoteUserInfo)
localUserDataSource.setUserInfo(remoteUserInfo)
}
}

0 comments on commit 21ccda8

Please sign in to comment.