Skip to content

Commit

Permalink
fix: Auth Service 생성시 authenticatorInterceptor 추가
Browse files Browse the repository at this point in the history
  • Loading branch information
junjange committed Dec 7, 2024
1 parent c8722e6 commit 2f24ce7
Showing 1 changed file with 33 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -67,14 +67,20 @@ object NetworkModule {
@Singleton
fun provideAuthService(
@Base baseUrl: BaseUrl,
authenticatorInterceptor: AuthorizationInterceptor,
converterFactory: Factory,
): AuthService =
Retrofit.Builder().baseUrl(baseUrl.url).client(
createOkHttpClient {
addInterceptor(ErrorResponseInterceptor())
addInterceptor(logging)
},
).addConverterFactory(converterFactory).build()
Retrofit
.Builder()
.baseUrl(baseUrl.url)
.client(
createOkHttpClient {
addInterceptor(authenticatorInterceptor)
addInterceptor(ErrorResponseInterceptor())
addInterceptor(logging)
},
).addConverterFactory(converterFactory)
.build()
.create(AuthService::class.java)

@Singleton
Expand All @@ -84,34 +90,40 @@ object NetworkModule {
authenticator: Authenticator,
authenticatorInterceptor: AuthorizationInterceptor,
converterFactory: Factory,
): Retrofit {
return Retrofit.Builder().baseUrl(baseUrl.url).client(
createOkHttpClient {
addInterceptor(authenticatorInterceptor)
authenticator(authenticator)
addInterceptor(ErrorResponseInterceptor())
addInterceptor(logging)
},
).addConverterFactory(converterFactory).build()
}
): Retrofit =
Retrofit
.Builder()
.baseUrl(baseUrl.url)
.client(
createOkHttpClient {
addInterceptor(authenticatorInterceptor)
authenticator(authenticator)
addInterceptor(ErrorResponseInterceptor())
addInterceptor(logging)
},
).addConverterFactory(converterFactory)
.build()

@Singleton
@Provides
fun provideStumpClient(
authenticator: Authenticator,
authenticatorInterceptor: AuthorizationInterceptor,
): StompClient {
return createOkHttpClient {
): StompClient =
createOkHttpClient {
addInterceptor(authenticatorInterceptor)
authenticator(authenticator)
addInterceptor(ErrorResponseInterceptor())
addInterceptor(logging)
}.let(::OkHttpWebSocketClient).let(
::StompClient,
)
}

private fun createOkHttpClient(interceptors: OkHttpClient.Builder.() -> Unit = { }): OkHttpClient =
OkHttpClient.Builder().callTimeout(Duration.ofMinutes(TIME_OUT_MINUTE))
.pingInterval(Duration.ofSeconds(PING_OUT_SECOND)).apply(interceptors).build()
OkHttpClient
.Builder()
.callTimeout(Duration.ofMinutes(TIME_OUT_MINUTE))
.pingInterval(Duration.ofSeconds(PING_OUT_SECOND))
.apply(interceptors)
.build()
}

0 comments on commit 2f24ce7

Please sign in to comment.