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

Commit

Permalink
Merge pull request #422 from GSM-MSG/feature/421_The_auto_login_is_so…
Browse files Browse the repository at this point in the history
…_short

🔀 :: (#421) - The auto login is so short
  • Loading branch information
Cjsghkd authored May 2, 2023
2 parents b04c393 + c1e6cad commit 54bd3f7
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,17 @@ package com.msg.gcms.data.remote.dto.auth.request

import com.google.gson.annotations.SerializedName
import okhttp3.MediaType.Companion.toMediaTypeOrNull
import okhttp3.RequestBody
import okhttp3.RequestBody.Companion.toRequestBody
import org.json.JSONObject

data class RefreshRequest(
@SerializedName("token")
val token: String
)

fun RefreshRequest.toRequestBody() =
this.toString().toRequestBody("application/json".toMediaTypeOrNull())
fun RefreshRequest.toRequestBody(): RequestBody {
return JSONObject().apply {
put("token", this@toRequestBody.token)
}.toString().toRequestBody("application/json".toMediaTypeOrNull())
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,8 @@ class LoginInterceptor @Inject constructor(
val request = chain.request()
val path = request.url.encodedPath
val method = request.method
val ignorePath = listOf(
"/auth"
)
val ignoreMethod = listOf(
"POST"
)
val ignorePath = listOf("/auth")
val ignoreMethod = listOf("POST")

ignorePath.forEachIndexed { index, s ->
if (s == path && ignoreMethod[index] == method) {
Expand Down
10 changes: 10 additions & 0 deletions app/src/main/java/com/msg/gcms/di/module/NetworkModule.kt
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.msg.gcms.di.module

import android.util.Log
import com.msg.gcms.BuildConfig
import com.msg.gcms.data.remote.network.api.ClubAPI
import com.msg.gcms.data.remote.network.api.AuthAPI
Expand All @@ -13,6 +14,7 @@ import dagger.Provides
import dagger.hilt.InstallIn
import dagger.hilt.components.SingletonComponent
import okhttp3.OkHttpClient
import okhttp3.logging.HttpLoggingInterceptor
import retrofit2.Retrofit
import retrofit2.converter.gson.GsonConverterFactory
import java.util.concurrent.TimeUnit
Expand All @@ -22,9 +24,16 @@ import javax.inject.Singleton
@InstallIn(SingletonComponent::class)
object NetworkModule {

@Provides
fun provideHttpLoggingInterceptor(): HttpLoggingInterceptor {
return HttpLoggingInterceptor { message -> Log.v("HTTP", message) }
.setLevel(HttpLoggingInterceptor.Level.BODY)
}

@Provides
@Singleton
fun provideOkhttpClient(
httpLoggingInterceptor: HttpLoggingInterceptor,
loginInterceptor: LoginInterceptor
): OkHttpClient {
return OkHttpClient.Builder()
Expand All @@ -35,6 +44,7 @@ object NetworkModule {
// 읽기 타임 아웃의 반대 방향. 얼마나 빨리 서버에 바이트를 보낼 수 있는지 확인
.writeTimeout(30, TimeUnit.SECONDS)
.addInterceptor(loginInterceptor)
.addInterceptor(httpLoggingInterceptor)
.build()
}

Expand Down

0 comments on commit 54bd3f7

Please sign in to comment.