Skip to content
This repository was archived by the owner on Dec 7, 2024. It is now read-only.

Commit 54bd3f7

Browse files
authored
Merge pull request #422 from GSM-MSG/feature/421_The_auto_login_is_so_short
🔀 :: (#421) - The auto login is so short
2 parents b04c393 + c1e6cad commit 54bd3f7

3 files changed

Lines changed: 19 additions & 8 deletions

File tree

app/src/main/java/com/msg/gcms/data/remote/dto/auth/request/RefreshRequest.kt

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,17 @@ package com.msg.gcms.data.remote.dto.auth.request
22

33
import com.google.gson.annotations.SerializedName
44
import okhttp3.MediaType.Companion.toMediaTypeOrNull
5+
import okhttp3.RequestBody
56
import okhttp3.RequestBody.Companion.toRequestBody
7+
import org.json.JSONObject
68

79
data class RefreshRequest(
810
@SerializedName("token")
911
val token: String
1012
)
1113

12-
fun RefreshRequest.toRequestBody() =
13-
this.toString().toRequestBody("application/json".toMediaTypeOrNull())
14+
fun RefreshRequest.toRequestBody(): RequestBody {
15+
return JSONObject().apply {
16+
put("token", this@toRequestBody.token)
17+
}.toString().toRequestBody("application/json".toMediaTypeOrNull())
18+
}

app/src/main/java/com/msg/gcms/data/remote/network/LoginInterceptor.kt

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,8 @@ class LoginInterceptor @Inject constructor(
2424
val request = chain.request()
2525
val path = request.url.encodedPath
2626
val method = request.method
27-
val ignorePath = listOf(
28-
"/auth"
29-
)
30-
val ignoreMethod = listOf(
31-
"POST"
32-
)
27+
val ignorePath = listOf("/auth")
28+
val ignoreMethod = listOf("POST")
3329

3430
ignorePath.forEachIndexed { index, s ->
3531
if (s == path && ignoreMethod[index] == method) {

app/src/main/java/com/msg/gcms/di/module/NetworkModule.kt

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package com.msg.gcms.di.module
22

3+
import android.util.Log
34
import com.msg.gcms.BuildConfig
45
import com.msg.gcms.data.remote.network.api.ClubAPI
56
import com.msg.gcms.data.remote.network.api.AuthAPI
@@ -13,6 +14,7 @@ import dagger.Provides
1314
import dagger.hilt.InstallIn
1415
import dagger.hilt.components.SingletonComponent
1516
import okhttp3.OkHttpClient
17+
import okhttp3.logging.HttpLoggingInterceptor
1618
import retrofit2.Retrofit
1719
import retrofit2.converter.gson.GsonConverterFactory
1820
import java.util.concurrent.TimeUnit
@@ -22,9 +24,16 @@ import javax.inject.Singleton
2224
@InstallIn(SingletonComponent::class)
2325
object NetworkModule {
2426

27+
@Provides
28+
fun provideHttpLoggingInterceptor(): HttpLoggingInterceptor {
29+
return HttpLoggingInterceptor { message -> Log.v("HTTP", message) }
30+
.setLevel(HttpLoggingInterceptor.Level.BODY)
31+
}
32+
2533
@Provides
2634
@Singleton
2735
fun provideOkhttpClient(
36+
httpLoggingInterceptor: HttpLoggingInterceptor,
2837
loginInterceptor: LoginInterceptor
2938
): OkHttpClient {
3039
return OkHttpClient.Builder()
@@ -35,6 +44,7 @@ object NetworkModule {
3544
// 읽기 타임 아웃의 반대 방향. 얼마나 빨리 서버에 바이트를 보낼 수 있는지 확인
3645
.writeTimeout(30, TimeUnit.SECONDS)
3746
.addInterceptor(loginInterceptor)
47+
.addInterceptor(httpLoggingInterceptor)
3848
.build()
3949
}
4050

0 commit comments

Comments
 (0)