# Best way to handle token refresh with async/await in a shared API client?

**URL:** <https://forums.swift.org/t/best-way-to-handle-token-refresh-with-async-await-in-a-shared-api-client/90937>\
**Category:** Using Swift\
**Created:** [November 20, 2026, 4:38pm UTC](https://forums.swift.org/t/best-way-to-handle-token-refresh-with-async-await-in-a-shared-api-client/90937 "2026-11-20T16:38:06Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![WeblynxBilal](https://avatars.discourse-cdn.com/v4/letter/w/c89c15/32.png) [@WeblynxBilal](https://forums.swift.org/u/WeblynxBilal)\
**Post date:** [November 20, 2026, 4:38pm UTC](https://forums.swift.org/t/best-way-to-handle-token-refresh-with-async-await-in-a-shared-api-client/90937/1 "2026-11-20T16:38:06Z")

</div>

In a couple of client iOS apps we have a shared API client built on URLSession and async/await. When the access token expires, several requests can fail at the same time, and each one tries to refresh the token on its own.

Right now we use an actor that holds the current token and a single in-flight refresh Task, so other callers await that same task instead of starting a new one. It works, but I am not sure about edge cases like the refresh itself failing or the app going to the background mid-refresh.

How are others structuring this? Is an actor with a shared Task the common pattern now, or is there a cleaner approach I am missing?
