From 93775cd2364152e76fe68c716be40ab0ad14f2e6 Mon Sep 17 00:00:00 2001 From: krrong Date: Sun, 1 Oct 2023 13:20:17 +0900 Subject: [PATCH] =?UTF-8?q?fix:=20OkHttpClient=EC=9D=98=20interceptor?= =?UTF-8?q?=EB=A5=BC=20AuthInterceptor=EB=A1=9C=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/com/now/naaga/di/ServiceModule.kt | 24 ++++--------------- 1 file changed, 4 insertions(+), 20 deletions(-) diff --git a/android/app/src/main/java/com/now/naaga/di/ServiceModule.kt b/android/app/src/main/java/com/now/naaga/di/ServiceModule.kt index 17f77cd3a..266411eb9 100644 --- a/android/app/src/main/java/com/now/naaga/di/ServiceModule.kt +++ b/android/app/src/main/java/com/now/naaga/di/ServiceModule.kt @@ -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 @@ -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 @@ -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