Application is getting redirected when calling getAccessTokenSilently() to get a new token when we have an active token

In my application we are using React SDK to authenticate a user. Our token expiry is of 60 mins and we have a requirement to refresh the token before 60 mins to get a new token for other subsequent API calls. For this we are calling the getAccessTokenSilently({detailedResponse: true, cacheMode: ‘off’}). “cacheMode : ‘off’” calls the token API and we get a new token. The issue which we are facing is that when we are calling the token API again with cacheMode: off the application reload automatically and we are re-directed to home screen. All the unsaved changes are lost. With cacheMode: ‘on/cache-only’ we get the same token again hence no APi call and hence no refresh but we get the same token which is not required. Any leads on this?

Hi @karan.udawat,

Welcome to the Auth0 Community!

What are you seeing in response to the request to get the token silently? Is the request failing and requiring a login?

@dan.woda i am getting the sucess response with new access token and ID token. It also does not require a login. But the issue is there is a redirect_uri parameter going with the token API call(I have tried overriding it with empty string also in getAccessTokenSilently() arguments) with is making the application to reload.

Payload-

Response -

Also, as per the documents if we make useRefreshToken= true the token will get reloaded after the token is expired but it is not happening currently. I am using @auth0/auth0-react": “^2.2.3” package

Thanks for the additional info.

I set up a test app to try and reproduce this issue. I can’t reproduce the issue with reloading if I use refresh tokens and getAccessTokenSilently({detailedResponse: true, cacheMode: ‘off’}).

In my test app, I get the token silently in the background and stay on the same page. I used the Auth0 React SDK Quickstarts: Call an API code, added useRefreshTokens: true to the provider, and {detailedResponse: true, cacheMode: ‘off’} to the call to getAccessTokenSilently.

Could you please share your provider setup? Omit sensitive data please.

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