# SPA get redirected every time access token needs to be refreshed

**URL:** <https://community.auth0.com/t/spa-get-redirected-every-time-access-token-needs-to-be-refreshed/65992>\
**Category:** Get Help\
**Tags:** auth0\
**Created:** [July 12, 2021, 12:56pm UTC](https://community.auth0.com/t/spa-get-redirected-every-time-access-token-needs-to-be-refreshed/65992 "2021-07-12T12:56:52Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![vcarel](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/vcarel/32/30498_2.png) [@vcarel](https://community.auth0.com/u/vcarel)\
**Post date:** [July 12, 2021, 12:56pm UTC](https://community.auth0.com/t/spa-get-redirected-every-time-access-token-needs-to-be-refreshed/65992/1 "2021-07-12T12:56:52Z")

</div>

Please include the following information in your post:

- **Which SDK this is regarding:** e.g. @auth0/auth0-react
- **SDK Version:** 1.5.0
- **Platform Version:** Chrome 91.0.4472.114

I noticed my SPA get redirected to auth0 everytime the access token expires (1 hour). Which means that users loose what they were doing when it happens (e.g. filling a form…). No need to say that it is pretty annoying !

I configured auth0 to use _rotating refresh tokens_. I presumed the SDK would call auth0 itself to renew the access token.

How may I avoid those redirects ? Is it a bug in the SDK ?

```auto
      <Auth0Provider
        audience={process.env.REACT_APP_AUTH0_AUDIENCE}
        cacheLocation="localstorage"
        clientId={getAuth0ClientId()}
        domain={process.env.REACT_APP_AUTH0_DOMAIN}
        redirectUri={window.location.origin}
        useRefreshTokens
      >
        <App />
      </Auth0Provider>

```

Thanks for your help !

---

<div class="post-metadata">

**Author:** ![sgo](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/sgo/32/13789_2.png) [@sgo](https://community.auth0.com/u/sgo)\
**Post date:** [July 12, 2021, 3:24pm UTC](https://community.auth0.com/t/spa-get-redirected-every-time-access-token-needs-to-be-refreshed/65992/2 "2021-07-12T15:24:41Z")

</div>

Hi @vcarel , welcome to the community!

I think you need to have instead `useRefreshTokens={true}` in your Auth0Provider config from looking at the quickstart docs. Then, provided the API your audience is pointed at has `Allow Offline Access` enabled, the SDK should be able to obtain one when the user logs in and store it for use whenever the `getAccessTokenSilently` method is called and carry out the request in a hidden iFrame to avoid disrupting the user.

- [Auth0 React SDK Quickstarts: Call an API](https://auth0.com/docs/quickstart/spa/react/02-calling-an-api)
- [https://auth0.github.io/auth0-react/interfaces/auth0\_provider.auth0provideroptions.html#userefreshtokens](https://auth0.github.io/auth0-react/interfaces/auth0_provider.auth0provideroptions.html#userefreshtokens)
- [API Settings](https://auth0.com/docs/get-started/dashboard/api-settings)

---

<div class="post-metadata">

**Author:** ![vcarel](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/vcarel/32/30498_2.png) [@vcarel](https://community.auth0.com/u/vcarel)\
**Post date:** [July 12, 2021, 3:33pm UTC](https://community.auth0.com/t/spa-get-redirected-every-time-access-token-needs-to-be-refreshed/65992/3 "2021-07-12T15:33:15Z")

</div>

Hi @sgo, thanks for answering so quickly!

Well, `useRefreshTokens` and `useRefreshTokens={true}` are equivalent. But I’ll check the other points. I said “I configured” for convenience, but that’s team work and I don’t have admin access to our Auth0 account - so the delay. I let you know the outcome by tomorrow.

Cheers,

---

<div class="post-metadata">

**Author:** ![vcarel](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/vcarel/32/30498_2.png) [@vcarel](https://community.auth0.com/u/vcarel)\
**Post date:** [July 15, 2021, 8:00am UTC](https://community.auth0.com/t/spa-get-redirected-every-time-access-token-needs-to-be-refreshed/65992/4 "2021-07-15T08:00:36Z")

</div>

Hi @sgo, sorry to come back a bit late, but there is a good news. What was missing was indeed to enable `Allow Offline Access`. Then we don’t have anymore redirects, and the SDK refreshes access tokens with XHR requests.

A big thanks for your support.

---

<div class="post-metadata">

**Author:** ![konrad.sopala](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/konrad.sopala/32/13516_2.png) [@konrad.sopala](https://community.auth0.com/u/konrad.sopala)\
**Post date:** [July 15, 2021, 9:56am UTC](https://community.auth0.com/t/spa-get-redirected-every-time-access-token-needs-to-be-refreshed/65992/5 "2021-07-15T09:56:42Z")

</div>

Glad it all came together! Here for you!

---

<div class="post-metadata">

**Author:** ![konrad.sopala](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/konrad.sopala/32/13516_2.png) [@konrad.sopala](https://community.auth0.com/u/konrad.sopala)\
**Post date:** [July 29, 2021, 10:23am UTC](https://community.auth0.com/t/spa-get-redirected-every-time-access-token-needs-to-be-refreshed/65992/6 "2021-07-29T10:23:38Z")

</div>


