# Storing Auth0 tokens in session storage instead of local storage

**URL:** <https://community.auth0.com/t/storing-auth0-tokens-in-session-storage-instead-of-local-storage/63154>\
**Category:** Get Help\
**Tags:** auth0-spa-js, id\_token, access-token\
**Created:** [May 21, 2021, 10:39am UTC](https://community.auth0.com/t/storing-auth0-tokens-in-session-storage-instead-of-local-storage/63154 "2021-05-21T10:39:30Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![harigovind2295](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/harigovind2295/32/29455_2.png) [@harigovind2295](https://community.auth0.com/u/harigovind2295)\
**Post date:** [May 21, 2021, 10:39am UTC](https://community.auth0.com/t/storing-auth0-tokens-in-session-storage-instead-of-local-storage/63154/1 "2021-05-21T10:39:30Z")

</div>

Hi Team,

I am using auth0-spa-js in React JS. I am using gettokensilently method to get the token from Auth0 server and currently setting the cachelocation to local storage. Is there any way to tell Auth0 to store the token in session storage instead of local storage , so that I can maintain different users session in different browser tabs as part of my requirement.

Thanks in advance,  
Hari

---

<div class="post-metadata">

**Author:** ![stephanie.chamblee](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/stephanie.chamblee/32/26087_2.png) [@stephanie.chamblee](https://community.auth0.com/u/stephanie.chamblee)\
**Post date:** [May 21, 2021, 12:41pm UTC](https://community.auth0.com/t/storing-auth0-tokens-in-session-storage-instead-of-local-storage/63154/3 "2021-05-21T12:41:13Z")

</div>

Hi @harigovind2295,

Currently, `auth0-spa-js` only supports caching tokens in memory or local storage: [Token Storage](https://auth0.com/docs/security/data-security/token-storage#single-page-app-scenarios)

You may be able to maintain two user sessions in different tabs by setting sessions to non-persisting (Settings \> Advanced):

 ![Screen Shot 2021-05-21 at 8.38.44 AM](https://global.discourse-cdn.com/auth0/original/3X/1/a/1ad1f1c71f9fe69b2395d06777e378b737f9a8f9.png)

And using memory instead of local storage in the app:

```auto
ReactDOM.render(
  <Auth0Provider
    domain={config.domain}
    clientId={config.clientId}
    redirectUri={window.location.origin}
    audience={config.audience}
    scope="read:current_user update:current_user_metadata"
    onRedirectCallback={onRedirectCallback}
    useRefreshTokens={true}
    cacheLocation="memory"
  >
    <App />
  </Auth0Provider>,
  document.getElementById("root")
);

```

Tokens stored in memory won’t be available in new tabs, and if the session is set to non-persisting, silent auth won’t log the same user in, so you should be able to log a different user in on the other tab.

---

<div class="post-metadata">

**Author:** ![harigovind2295](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/harigovind2295/32/29455_2.png) [@harigovind2295](https://community.auth0.com/u/harigovind2295)\
**Post date:** [May 24, 2021, 8:09am UTC](https://community.auth0.com/t/storing-auth0-tokens-in-session-storage-instead-of-local-storage/63154/4 "2021-05-24T08:09:15Z")

</div>

Hi @stephanie.chamblee ,

In my application, cacheLocation has been set to “localstorage” in Auth0Provider component.

> [@stephanie.chamblee](#):
>
> ```auto
> ReactDOM.render(
> <Auth0Provider
> domain={config.domain}
> clientId={config.clientId}
> redirectUri={window.location.origin}
> audience={config.audience}
> scope="read:current_user update:current_user_metadata"
> onRedirectCallback={onRedirectCallback}
> useRefreshTokens={true}
> cacheLocation="localstorage"
> >
> <App />
> </Auth0Provider>,
> document.getElementById("root")
> );
> 
> ```

And lot of logic has been written internally in application to read the data from localstorage. But now there is one requirement to get access token/ID token for other users for which I am using getAccessTokenSilently method in useAuth0 hooks.

> const { user, logout, getAccessTokenSilently, getIdTokenClaims } = useAuth0();

But I don’t want the token which I am generating using getAccessTokenSilently method to be stored in localstorage but it does which I presume it picks cacheLocation settings from Auth0Provider component. Is there any way to override the cacheLocation in getAccessTokenSilently method or using the useAuth0 hooks.

Thanks in advance,  
Hari.

---

<div class="post-metadata">

**Author:** ![stephanie.chamblee](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/stephanie.chamblee/32/26087_2.png) [@stephanie.chamblee](https://community.auth0.com/u/stephanie.chamblee)\
**Post date:** [May 24, 2021, 11:36am UTC](https://community.auth0.com/t/storing-auth0-tokens-in-session-storage-instead-of-local-storage/63154/5 "2021-05-24T11:36:21Z")

</div>

Hi @harigovind2295,

Unfortunately, if you require the Auth0Client to be configured with `localStorage` you won’t be able to maintain two user sessions in different tabs. You can use the `ignoreCache` in the `getAccessTokenSilently` ([API docs](https://auth0.github.io/auth0-spa-js/interfaces/gettokensilentlyoptions.html#ignorecache)), but there is not a similar option for `getIdTokenClaims`. For this use case, I believe you’d need to use memory for `cacheLocation`.

---

<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:** [June 8, 2021, 11:36am UTC](https://community.auth0.com/t/storing-auth0-tokens-in-session-storage-instead-of-local-storage/63154/6 "2021-06-08T11:36:26Z")

</div>

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