Skip to content

Commit

Permalink
fix: OkHttpClient의 interceptor를 AuthInterceptor로 변경
Browse files Browse the repository at this point in the history
  • Loading branch information
krrong committed Oct 1, 2023
1 parent 3abfcfd commit 93775cd
Showing 1 changed file with 4 additions and 20 deletions.
24 changes: 4 additions & 20 deletions android/app/src/main/java/com/now/naaga/di/ServiceModule.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package com.now.naaga.di

import com.jakewharton.retrofit2.converter.kotlinx.serialization.asConverterFactory
import com.now.naaga.BuildConfig
import com.now.naaga.NaagaApplication
import com.now.naaga.data.remote.retrofit.AuthInterceptor
import com.now.naaga.data.remote.retrofit.service.AdventureService
import com.now.naaga.data.remote.retrofit.service.AuthService
import com.now.naaga.data.remote.retrofit.service.PlaceService
Expand All @@ -13,7 +13,6 @@ import dagger.Provides
import dagger.hilt.InstallIn
import dagger.hilt.components.SingletonComponent
import kotlinx.serialization.json.Json
import okhttp3.Interceptor
import okhttp3.MediaType.Companion.toMediaType
import okhttp3.OkHttpClient
import retrofit2.Retrofit
Expand All @@ -26,24 +25,9 @@ class ServiceModule {

@Singleton
@Provides
fun createInterceptor(): Interceptor = Interceptor { chain ->
val token: String = NaagaApplication.authDataSource.getAccessToken() ?: ""
with(chain) {
val newRequest = request().newBuilder()
.addHeader("Authorization", "Bearer $token")
.addHeader("Content-Type", "application/json")
.build()
proceed(newRequest)
}
}

@Singleton
@Provides
fun createOkHttpClient(interceptor: Interceptor): OkHttpClient {
return OkHttpClient.Builder().apply {
addInterceptor(interceptor)
}.build()
}
fun provideOkHttpClient(): OkHttpClient = OkHttpClient.Builder().apply {
addInterceptor(AuthInterceptor())
}.build()

@Singleton
@Provides
Expand Down

0 comments on commit 93775cd

Please sign in to comment.