# "Token could not be decoded or is missing in DB"

**URL:** <https://community.auth0.com/t/token-could-not-be-decoded-or-is-missing-in-db/168701>\
**Category:** Get Help\
**Tags:** reusable-refresh-tokens, sessions\
**Created:** [January 15, 2025, 5:29am UTC](https://community.auth0.com/t/token-could-not-be-decoded-or-is-missing-in-db/168701 "2025-01-15T05:29:06Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![tom27](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/tom27/32/70522_2.png) [@tom27](https://community.auth0.com/u/tom27)\
**Post date:** [January 15, 2025, 5:29am UTC](https://community.auth0.com/t/token-could-not-be-decoded-or-is-missing-in-db/168701/1 "2025-01-15T05:29:06Z")

</div>

I recently updated [auth0-spa-js](https://github.com/auth0/auth0-spa-js). Since then a problem occurs with the following two symptoms.

Symptom 1: Calls to `auth0.getTokenSilently()` now seem to throw an exception some of the time (perhaps after 1 hour of inactivity?). I can mitigate this by catching the exception and calling `auth0.loginWithRedirect()`.

Symptom 2: I see lots of “Token could not be decoded or is missing in DB” error logs in auth0 monitoring.

[Refresh Token Exchange - fertft Events "Token could not be decoded or is missing in DB"](https://community.auth0.com/t/refresh-token-exchange-fertft-events-token-could-not-be-decoded-or-is-missing-in-db/151632) indicates this is caused by reuse of a refresh token, which seems to be entirely handled in the library itself.

Is this a bug or am I doing something wrong?

Here’s the gist of how I’m using the lib.

```auto
authClient = new Auth0Client({
  clientId: CLIENT_ID,
  domain: DOMAIN,
  authorizationParams: {
    redirect_uri: redirectUri,
    audience: AUDIENCE
  },
  cacheLocation: "localstorage",
  useRefreshTokens: true,
});

authClient.checkSession()

// other code

function callAPI(endpoint, config = {}) {
  let token = undefined;
  try {
    token = await authClient.getTokenSilently();
  } catch (error) {
    console.error('Token retrieval failed:', error);
    await authClient.loginWithRedirect(); // <-- New to mitigate recent issue
  }

  // call some api endpoint with the token
}

```

---

<div class="post-metadata">

**Author:** ![rueben.tiow](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/rueben.tiow/32/11646_2.png) [@rueben.tiow](https://community.auth0.com/u/rueben.tiow)\
**Post date:** [January 15, 2025, 8:11pm UTC](https://community.auth0.com/t/token-could-not-be-decoded-or-is-missing-in-db/168701/3 "2025-01-15T20:11:15Z")

</div>

Hi @tom27,

Welcome to the Auth0 Community!

For the first symptom, the token is expiring in 1 hour because you have set your API’s **Token Expiration** and **Token Expiration for Browser Flows** to 1 hour (3600 seconds). This will cause you to see the `Login Required` error and require reauthentication to get a new valid access token. Please refer to our [Change access\_token Expiration Time](https://community.auth0.com/t/change-access-token-expiration-time/122560) knowledge article.

As for the second symptom, it seems to be happening because it failed to exchange a refresh token for an access token. In this situation, you must ensure you are not reusing your refresh tokens when you have refresh token rotation enabled. You must use a new refresh token that was issued after getting a new access token and refresh token. (Reference: [Use Refresh Token Rotation](https://auth0.com/docs/secure/tokens/refresh-tokens/use-refresh-token-rotation))

Thanks,  
Rueben

---

<div class="post-metadata">

**Author:** ![tom27](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/tom27/32/70522_2.png) [@tom27](https://community.auth0.com/u/tom27)\
**Post date:** [January 15, 2025, 11:39pm UTC](https://community.auth0.com/t/token-could-not-be-decoded-or-is-missing-in-db/168701/4 "2025-01-15T23:39:19Z")

</div>

> [@rueben.tiow](#):
>
> you must ensure you are not reusing your refresh tokens when you have refresh token rotation enabled. You must use a new refresh token that was issued after getting a new access token and refresh token. (Reference: [Use Refresh Token Rotation](https://auth0.com/docs/secure/tokens/refresh-tokens/use-refresh-token-rotation))

It looks like [this code](https://github.com/auth0/auth0-spa-js/blob/f2e566849efa398ca599daf9ebdfbbd62fcb1894/src/Auth0Client.ts#L700) is where the API call for refresh tokens is happening. It also looks like it’s intended to be called multiple times concurrently. It has an optimization to avoid latency on a cache call, perhaps I’m running into that?

---

<div class="post-metadata">

**Author:** ![tom27](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/tom27/32/70522_2.png) [@tom27](https://community.auth0.com/u/tom27)\
**Post date:** [January 29, 2025, 8:05pm UTC](https://community.auth0.com/t/token-could-not-be-decoded-or-is-missing-in-db/168701/5 "2025-01-29T20:05:16Z")

</div>

Still getting these “Token could not be decoded or is missing in DB”, some guidance would be great.

---

<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:** [February 12, 2025, 8:05pm UTC](https://community.auth0.com/t/token-could-not-be-decoded-or-is-missing-in-db/168701/6 "2025-02-12T20:05:21Z")

</div>

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