Hi! I’m using AppAuth on Android to login to my backend and coroutines (ktor) on my transport layer to call APIs on that backend. I need to pass an access token to each of my calls. Using AppAuth I refresh this token with the
AuthState.performActionWithFreshTokens(callback: (freshToken: String?))
which uses a callback to give me the fresh token. And my transport service uses coroutines, something like:
class TransportService {
suspend fun getAllTasks(): List<Task> {
authState.performActionWithFreshToken() { freshToken ->
return ktorClient.get<List<Task>>()
}
}
}
Now, I have an error where I use the ktor client:
suspend function can be called only within coroutines scope
. That is because the callback function is not a coroutine scope. If I create a new scope within the callback, will this work well with the main function? What can I do to keep my transport with suspend function and not use completion handler everywhere? Thanks 🙂