Users getting logged out with "Unsuccessful Refresh Token exchange, reused refresh token detected"

Open
#929 19 comments 1 reaction 0 assignees View on GitHub

Maintainers usually reply within 1 day

Nobody has claimed this yet.

Assessment

Difficulty
4/5
Estimated time
3-5 days
Newbie friendliness
38/100
Issue type
Bug
Clarity
Needs clarification
Activity status
Active
Tech stack
react, typescript

Research direction

Start with the auth0-react Sample-01 app and inspect the Auth0Provider configuration and getAccessTokenSilently usage described in the report. Trace refresh-token handling with cacheLocation="localstorage" and useRefreshTokens enabled, then reproduce the intermittent exchange failure if possible. Done means the cause of the reused-token logout is identified and the affected behavior is verified across the reported environments.

Written by the indexing model from the issue text.

Description

bug
Checklist
Description

Our usage of Auth0 is pretty simple. After the user has been logged in we just attach the access token to network calls and verify them server side.

const useApi = (): Api => {
  const { getAccessTokenSilently } = useAuth0()
  const backend = axios.create({ baseURL: apiUri, timeout: 10000 })
  backend.interceptors.request.use(
    async config => {
      const accessToken = await getAccessTokenSilently()
      config.headers["Authorization"] = `Bearer ${accessToken}`
      return config
    },

    async error => {}
  )
}  

We have gotten user reports that they get error in title. Our understanding is that this error is unrecoverable so we log the user out and force them to re-authenticate. We have a couple of thousand weekly users and this happens to maybe 2% of them.

One log id as an example:
90020251109193144192993000000000000001223372093304300940

Our top level provider:

 <Auth0Provider
        key={`${domain}-${clientId}-${audience}`} // This forces remount when values change
        domain={domain}
        clientId={clientId}
        authorizationParams={{
          redirect_uri: getFrontEndHost(),
          audience: audience,
        }}
        cacheLocation={"localstorage"}
        onRedirectCallback={onAuth0Redirect}
        useRefreshTokens={true}
      >
        <AppWithTheme />
</Auth0Provider>
Reproduction

Seems to happen randomly, a few times a week for affected users. Mostly on iOS and MacOS devices but we've also seen it happen on Windows machines.

Additional context

A similar issue happens when we use the react native version, but only for iOS devices. We allow overlap for expiring refresh tokens (120 seconds). Our refresh token are set to last one year, and we're currently seeing this multiple times a week for users.

auth0-react version

2.8.0

React version

19.1.0

Which browsers have you tested in?

Chrome, Safari

Dominant language
TypeScript
Stars
992
Forks
292
Avg merge
10h 29m
Merged PRs (30d)
24

Getting set up

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from auth0/auth0-react

All issues in auth0/auth0-react

Similar issues

More TypeScript issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.