# React SDK refresh access token

**URL:** <https://community.auth0.com/t/react-sdk-refresh-access-token/57869>\
**Category:** Get Help\
**Tags:** auth0\
**Created:** [February 15, 2021, 10:19am UTC](https://community.auth0.com/t/react-sdk-refresh-access-token/57869 "2021-02-15T10:19:56Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![antejadrija](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/antejadrija/32/12751_2.png) [@antejadrija](https://community.auth0.com/u/antejadrija)\
**Post date:** [February 15, 2021, 10:19am UTC](https://community.auth0.com/t/react-sdk-refresh-access-token/57869/1 "2021-02-15T10:19:56Z")

</div>

Hi guys

I’m using auth0 react SDK (@auth0/auth0-react v1.2.0) and I need to refresh the access token when it expires.  
Based on the docs I have to call `getAccessTokenSilently()` before every API request so the SDK will either retrieve it from the local cache or Auth0 server (if token has expired).

Since the SDK provides only hooks to call `getAccessTokenSilently()` I need to use it inside the components.  
It would be great if I don’t have to repeat this in every component but to be able to put it inside the e.g. Axios interceptor and have it only at one place.

Is there any other option to solve this or I missed something from the docs?

Thank you  
Ante

---

<div class="post-metadata">

**Author:** ![stephanie.chamblee](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/stephanie.chamblee/32/26087_2.png) [@stephanie.chamblee](https://community.auth0.com/u/stephanie.chamblee)\
**Post date:** [February 16, 2021, 7:48pm UTC](https://community.auth0.com/t/react-sdk-refresh-access-token/57869/3 "2021-02-16T19:48:15Z")

</div>

Hi @antejadrija,

Welcome to the Community!

You may want to take a look at the gist which allows the app to access Auth0 client outside of the `Auth0Provider` wrapper: [Using @auth0/auth0-spa-js outside of a React Component - #4 by klequis](https://community.auth0.com/t/using-auth0-auth0-spa-js-outside-of-a-react-component/27805/4)

---

<div class="post-metadata">

**Author:** ![antejadrija](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/antejadrija/32/12751_2.png) [@antejadrija](https://community.auth0.com/u/antejadrija)\
**Post date:** [February 17, 2021, 7:40am UTC](https://community.auth0.com/t/react-sdk-refresh-access-token/57869/4 "2021-02-17T07:40:29Z")

</div>

Hi @stephanie.chamblee

This is useful.  
The only downside is that I need to switch from auth0-react to auth0-spa-js.

auth0-react is awesome SDK and the only thing I’m missing is this.  
If you can provide `getAccessTokenSilently()` outside of hooks it would make a huge difference. Otherwise we have to make our components dirty and copy paste the code in many places, or to switch to auth0-spa-js.

Thank you for your help.  
Ante

---

<div class="post-metadata">

**Author:** ![system](https://global.discourse-cdn.com/auth0/original/3X/b/5/b560f266932fcce5d57f09a6595bd50518cae3f3.jpeg) [@system](https://community.auth0.com/u/system)\
**Post date:** [March 4, 2021, 7:41am UTC](https://community.auth0.com/t/react-sdk-refresh-access-token/57869/5 "2021-03-04T07:41:16Z")

</div>

This topic was automatically closed 15 days after the last reply. New replies are no longer allowed.
