Maryam Memarzadeh
Maryam Memarzadeh

Reputation: 236

Refresh auth token in Ktor while using koin

I was using Koin as dependency Injection library to create the ktor HttpClient:

val AppModule = module {
    single { provideClientService() }
}

fun provideClientService(preferences: SharedPreferences): HttpClient {

install(Auth){
    bearer {
        loadTokens {
            BearerTokens(sharedPreferences.getString("accessToken",""))      
        }
    }
}}

but after the user login the accessToken is not updated.

I think it is because of the different scopes in koin. there is 3 kind of scopes in koin:

so I changed the client definition to factory , because I want it to be updated after getting a new token. and now I wonder is it correct?

val AppModule = module {
    factory { provideClientService() }
}

Upvotes: 0

Views: 1083

Answers (1)

Related Questions