Skip to content

Commit

Permalink
#11 / [FEAT] Login에 interceptor 구현
Browse files Browse the repository at this point in the history
Login에 interceptor 구현
  • Loading branch information
Marchbreeze committed May 20, 2023
1 parent 95380fc commit b0c5d9a
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 2 deletions.
2 changes: 2 additions & 0 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -70,4 +70,6 @@ dependencies {
// define any required OkHttp artifacts without version
implementation("com.squareup.okhttp3:okhttp")
implementation("com.squareup.okhttp3:logging-interceptor")


}
10 changes: 10 additions & 0 deletions app/src/main/java/org/android/go/sopt/module/AuthApiFactory.kt
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,28 @@ import com.jakewharton.retrofit2.converter.kotlinx.serialization.asConverterFact
import kotlinx.serialization.ExperimentalSerializationApi
import kotlinx.serialization.json.Json
import okhttp3.MediaType.Companion.toMediaType
import okhttp3.OkHttpClient
import okhttp3.logging.HttpLoggingInterceptor
import org.android.go.sopt.BuildConfig
import org.android.go.sopt.data.service.AuthService
import retrofit2.Retrofit

object AuthApiFactory {
private const val BASE_URL = BuildConfig.AUTH_BASE_URL

private val client by lazy {
OkHttpClient.Builder().addInterceptor(HttpLoggingInterceptor().apply {
level =
if (BuildConfig.DEBUG) HttpLoggingInterceptor.Level.BODY else HttpLoggingInterceptor.Level.NONE
}).build()
}

@OptIn(ExperimentalSerializationApi::class)
val retrofit: Retrofit by lazy {
Retrofit.Builder()
.baseUrl(BASE_URL)
.addConverterFactory(Json.asConverterFactory("application/json".toMediaType()))
.client(client)
.build()
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@ class LoginViewModel : ViewModel() {
private val _errorResult: MutableLiveData<String> = MutableLiveData()
val errorResult: LiveData<String> = _errorResult

private lateinit var binding: ActivityLoginBinding

fun login(id: String, password: String) {
authService.login(
LoginRequestDTO(
Expand Down

0 comments on commit b0c5d9a

Please sign in to comment.