# Suggested approach for avoiding stale access token with ApiProxyConnector?

**URL:** <https://discuss.elastic.co/t/suggested-approach-for-avoiding-stale-access-token-with-apiproxyconnector/383392>\
**Category:** Elasticsearch\
**Tags:** searchui\
**Created:** [November 12, 2025, 12:36pm UTC](https://discuss.elastic.co/t/suggested-approach-for-avoiding-stale-access-token-with-apiproxyconnector/383392 "2025-11-12T12:36:49Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![mansn](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/mansn/32/145730_2.png) [@mansn](https://discuss.elastic.co/u/mansn)\
**Post date:** [November 12, 2025, 12:36pm UTC](https://discuss.elastic.co/t/suggested-approach-for-avoiding-stale-access-token-with-apiproxyconnector/383392/1 "2025-11-12T12:36:49Z")

</div>

Hi, I’m using `@elastic/search-ui-elasticsearch-connector/api-proxy` to create a connector for my backend (and the backend implements the **[ElasticsearchAPIConnector](https://www.elastic.co/docs/reference/search-ui/api-connectors-elasticsearch#api-connectors-elasticsearch-doc-reference)**).

My backend endpoints requires an Bearer token to be passed on the `authorization` header, so I’m passing that in the `fetchOptions` when creating the connector.

**The problem**

Eventually the access token expires, but I have a refresh token so that I can get a new access token. However, I need to create a new instance of the connector to pass a new token.

**Suggested solution**

I believe this problem could be solved by having `fetchOptions` accepting a function which could dynamically return headers (including a fresh access token).

Currently I’m looking into the best way to workaround this in my application, and it’s probably going to be a class that extends APIProxyConnector and overrides the methods to “inject” fresh headers, if that makes sense. But it would be nice I could avoid that (and I think passing a function to `fetchOptions` could work).

Has anyone else faced this issue as well? How did you solve it? Have I missed anything?

Thanks in advance!
