# How to check if user has logged out in another tab?

**URL:** <https://community.auth0.com/t/how-to-check-if-user-has-logged-out-in-another-tab/56324>\
**Category:** Get Help\
**Tags:** react-sdk, auth0-react, react\
**Created:** [January 17, 2021, 3:03am UTC](https://community.auth0.com/t/how-to-check-if-user-has-logged-out-in-another-tab/56324 "2021-01-17T03:03:10Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![denyomonogatari](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/denyomonogatari/32/26987_2.png) [@denyomonogatari](https://community.auth0.com/u/denyomonogatari)\
**Post date:** [January 17, 2021, 3:03am UTC](https://community.auth0.com/t/how-to-check-if-user-has-logged-out-in-another-tab/56324/1 "2021-01-17T03:03:10Z")

</div>

I have created an SPA using auth0-react. If I start with two logged in tabs of my web application and logout in one tab of my browser, what function, variable, or technique can I use to detect that the user is no longer logged in when I switch to the other tab? This would prevent the user from making any changes in the application until the user logs in again.

---

<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:** [January 19, 2021, 8:46pm UTC](https://community.auth0.com/t/how-to-check-if-user-has-logged-out-in-another-tab/56324/3 "2021-01-19T20:46:15Z")

</div>

Hi @denyomonogatari,

Welcome to the Community!

I am doing some research on this and I will let you know what I find!

Stephanie

---

<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:** [January 20, 2021, 6:26pm UTC](https://community.auth0.com/t/how-to-check-if-user-has-logged-out-in-another-tab/56324/4 "2021-01-20T18:26:08Z")

</div>

It looks like if you set the `cacheLocation` on the `Auth0Provider` to ‘localstorage’ other tabs will be able to pick up that the user has logged out.

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

```

Note about local storage from [this topic](https://community.auth0.com/t/trying-the-new-refresh-token-rotation-in-a-react-spa-are-3rd-party-cookies-supposed-to-be-required/41151/10):

> [@Trying the new Refresh Token Rotation in a React SPA. Are 3rd party cookies supposed to be required?](https://community.auth0.com/t/trying-the-new-refresh-token-rotation-in-a-react-spa-are-3rd-party-cookies-supposed-to-be-required/41151/11):
>
> One thing to do right now to help is ensure that your application is mitigated in the best way possible from XSS attacks from being successful in the first instance:
> 
> - Keep the amount of third-party JavaScript being used to a minimum, and only from trusted sources
> - Use as short an expiry time on your access tokens as is practical

---

<div class="post-metadata">

**Author:** ![denyomonogatari](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/denyomonogatari/32/26987_2.png) [@denyomonogatari](https://community.auth0.com/u/denyomonogatari)\
**Post date:** [January 21, 2021, 1:18am UTC](https://community.auth0.com/t/how-to-check-if-user-has-logged-out-in-another-tab/56324/5 "2021-01-21T01:18:26Z")

</div>

Just what I needed thank you!  
For the sake of completeness I can catch the OAuthError when trying to call getAccessTokenSilently().

---

<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:** [January 21, 2021, 11:54am UTC](https://community.auth0.com/t/how-to-check-if-user-has-logged-out-in-another-tab/56324/6 "2021-01-21T11:54:44Z")

</div>

Thanks for including the `getAccessTokenSilently` piece!

---

<div class="post-metadata">

**Author:** ![konrad.sopala](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/konrad.sopala/32/13516_2.png) [@konrad.sopala](https://community.auth0.com/u/konrad.sopala)\
**Post date:** [January 26, 2021, 10:01am UTC](https://community.auth0.com/t/how-to-check-if-user-has-logged-out-in-another-tab/56324/8 "2021-01-26T10:01:39Z")

</div>

Previous message deleted due to SPAM reasons.

---

<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 10, 2021, 10:01am UTC](https://community.auth0.com/t/how-to-check-if-user-has-logged-out-in-another-tab/56324/9 "2021-02-10T10:01:49Z")

</div>

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