Skip to content

Commit

Permalink
Merge pull request #170 from Team-Sopetit/feature/#169-hotfix-token-r…
Browse files Browse the repository at this point in the history
…eponse-close

#169 [hotfix] 토큰 재발급 이슈
  • Loading branch information
stellar-halo authored Mar 15, 2024
2 parents 99bebdb + 79ab9d4 commit 2fdc042
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 16 deletions.
4 changes: 2 additions & 2 deletions app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,10 @@ android {
applicationId = "com.sopetit.softie"
minSdk = 28
targetSdk = 34
versionCode = 1
versionCode = 6
versionName = "1.0.0"
testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
buildConfigField("String", "BASE_URL", getApiKey("BASE_URL"))
buildConfigField("String", "BASE_URL", getApiKey("DEV_BASE_URL"))
buildConfigField("String", "KAKAO_NATIVE_APP_KEY", getApiKey("KAKAO_NATIVE_APP_KEY"))
manifestPlaceholders["KAKAO_REDIRECT_SCHEME"] = getApiKey("KAKAO_REDIRECT_SCHEME")
}
Expand Down
30 changes: 17 additions & 13 deletions app/src/main/java/com/sopetit/softie/di/RetrofitModule.kt
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import okhttp3.MediaType.Companion.toMediaType
import okhttp3.OkHttpClient
import okhttp3.logging.HttpLoggingInterceptor
import retrofit2.Retrofit
import timber.log.Timber
import java.util.concurrent.TimeUnit
import javax.inject.Qualifier
import javax.inject.Singleton
Expand Down Expand Up @@ -49,26 +50,29 @@ object RetrofitModule {
.build()
)
when (response.code) {
EXPIRED_TOKEN -> {
response.close()

EXPIRED_TOKEN -> try {
runBlocking {
refreshTokenRepository.postRefreshToken().onSuccess { accessToken ->
refreshTokenRepository.setAccessToken(accessToken.accessToken)
response = chain.proceed(
request
.newBuilder()
.addHeader(CONTENT_TYPE, APPLICATION_JSON)
.addHeader(
AUTHORIZATION,
BEARER + localDataSource.accessToken
)
.build()
)
}
}
response.close()

val newRequest = chain.request()
var newResponse = chain.proceed(
newRequest
.newBuilder()
.addHeader(CONTENT_TYPE, APPLICATION_JSON)
.addHeader(AUTHORIZATION, BEARER + localDataSource.accessToken)
.build()
)
return@Interceptor newResponse
} catch (t: Throwable) {
Timber.e(t.message)
}
}
response
return@Interceptor response
}

@Provides
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,14 @@ class LoginViewModel @Inject constructor(

val kakaoLoginCallback: (OAuthToken?, Throwable?) -> Unit = { token, error ->
KakaoLoginCallback { accessToken ->
_isKakaoLogin.value = true
initTokenUseCase(
accessToken = accessToken,
refreshToken = "",
isMemberDollExist = false,
isSignedUp = false
)
}.handleResult(token, error)
_isKakaoLogin.value = true
}

fun postLogin() {
Expand Down

0 comments on commit 2fdc042

Please sign in to comment.