# Can't get token from local storage

**URL:** <https://community.auth0.com/t/cant-get-token-from-local-storage/186443>\
**Category:** Get Help\
**Tags:** rotating-refresh-tokens, sessions\
**Created:** [May 7, 2025, 5:30pm UTC](https://community.auth0.com/t/cant-get-token-from-local-storage/186443 "2025-05-07T17:30:32Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![trevordammon](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/trevordammon/32/13337_2.png) [@trevordammon](https://community.auth0.com/u/trevordammon)\
**Post date:** [May 7, 2025, 5:30pm UTC](https://community.auth0.com/t/cant-get-token-from-local-storage/186443/1 "2025-05-07T17:30:32Z")

</div>

I am implementing a React sign on with local storage. I chose local storage because I don’t want my users to need to reauth every time they refresh the page.

The problem I am having is that I seem unable to pull the token from local storage with `getAccessTokenSilently()`. I do however have access to local storage with thee typical JavaScript methods.

My implementation is straight forward:

```auto
  <React.StrictMode>
    <Auth0Provider
      domain={domain}
      clientId={clientId}
      authorizationParams={{
        redirect_uri: window.location.origin,
        audience: audience,
        scope: "openid profile email offline_access",
      }}
      useRefreshTokens={true}
      cacheLocation="localstorage"
    >
      <BrowserRouter>
        <AppRoutes />
      </BrowserRouter>
    </Auth0Provider>
  </React.StrictMode>

```

and

```auto
  useEffect(() => {
    const checkUsername = async () => {
      if (isAuthenticated) {
        try {
          const token = await getAccessTokenSilently({
            authorizationParams: {
              audience: AUTH0_AUDIENCE,
              scope: "openid profile email offline_access",
            },
          });

          if (!token) {
            throw new Error("Access token is undefined");
          }

          console.log("Token available:", !!token);

          const response = await fetch("/api/v1/users/me", {
            headers: {
              Authorization: `Bearer ${token}`,
            },
          });

          if (!response.ok) {
            throw new Error(`HTTP error! status: ${response.status}`);
          }

          const data = await response.json();
          setHasUsername(!!data.username);
        } catch (error) {
          console.error("Failed to check username:", error);
          setHasUsername(false);
        }
      }
      setCheckingUsername(false);
    };

    checkUsername();
  }, [isAuthenticated, getAccessTokenSilently]);

```

As I research the issue more it seems like the problem is that `getAccessTokenSilently` uses some type of Iframe which is blocked from accessing local storage by the browser.

Surely their must be a way to use Auth0 with common browsers and not require a user to reauth on every page refresh.

---

<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:** [May 9, 2025, 5:08pm UTC](https://community.auth0.com/t/cant-get-token-from-local-storage/186443/3 "2025-05-09T17:08:30Z")

</div>

Hi @trevordammon,

Thanks for your question.

I have reviewed your code snippet and noticed that you passed in an `audience` to the [`getAccessTokenSilently()`](https://auth0.github.io/auth0-react/interfaces/Auth0ContextInterface.html#getAccessTokenSilently) method, which, according to the documentation, results in the SDK always falling back to using an iframe to make the token exchange.

If the access token you are trying to retrieve has the same audience as the one you are requesting, you could try omitting this to allow it to access local storage.

Let me know how this goes for you.

Regards,  
Rueben

---

<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:** [May 23, 2025, 5:08pm UTC](https://community.auth0.com/t/cant-get-token-from-local-storage/186443/4 "2025-05-23T17:08:54Z")

</div>

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