getTokenSilently() is slower than expected


I use the @auth0/auth0-spa-js library version 1.6.2 in my React app. I followed this tutorial and the authentication flow works fine.
However there’s a thing which bugs me a little bit. During data fetching I follow the pattern mentioned in the tutorial:

  const token = await getTokenSilently();

  const response = await fetch("/api/external", {
    headers: {
      Authorization: `Bearer ${token}`

I get the token as expected without a network request in normal cases, however it takes longer than I expected. I checked it with various tools and it usually takes about 50ms which seems a too long to me. I did this test on a 2018 MacBookPro, I guess it might take longer on weaker devices.

Do you know any workaround?


1 Like

Hi @lkiss

The code for getTokenSilently is fairly simple when there’s a cache hit (code at but there’s a usage of browser-tabs-lock to ensure multiple tabs play nicely together. This could be getting in the way of optimal performance.
If you have written tests or have other supporting information on this, I suggest starting a thread at the auth0-spa-js repository issues section, so that the team can look into this.

1 Like