# localStorage & Require log in after feature not working

**URL:** <https://community.auth0.com/t/localstorage-require-log-in-after-feature-not-working/114216>\
**Category:** Get Help\
**Tags:** configuration, application\
**Created:** [August 22, 2023, 1:34pm UTC](https://community.auth0.com/t/localstorage-require-log-in-after-feature-not-working/114216 "2023-08-22T13:34:18Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![dally](https://upload.wikimedia.org/wikipedia/commons/thumb/7/7c/User_font_awesome.svg/768px-User_font_awesome.svg.png) [@dally](https://community.auth0.com/u/dally)\
**Post date:** [August 22, 2023, 1:34pm UTC](https://community.auth0.com/t/localstorage-require-log-in-after-feature-not-working/114216/1 "2023-08-22T13:34:18Z")

</div>

Hi all, I have a Vue app that I’ve got working well with Auth0 bar one bit. Since changing `cacheLocation` to `localStorage`, the `Require log in after` setting in the Auth0 settings page has no affect.

I want my application to automatically log users out after 480mins.

The page itself is not showing any data which is good as I’ve got refresh token expiration set to 480mins too but it’s not ideal that a user is still logged in.

What is the best way around this?

---

<div class="post-metadata">

**Author:** ![dally](https://upload.wikimedia.org/wikipedia/commons/thumb/7/7c/User_font_awesome.svg/768px-User_font_awesome.svg.png) [@dally](https://community.auth0.com/u/dally)\
**Post date:** [August 24, 2023, 10:32am UTC](https://community.auth0.com/t/localstorage-require-log-in-after-feature-not-working/114216/2 "2023-08-24T10:32:35Z")

</div>

Quite surprised no one has come across this issue considering the number of websites running on Vue, React, Svelte, etc.

So the way I have solved this is by doing the following in my router file. I don’t know whether this is the most efficient method but it’s working.

```auto
const tokenClaims = await getIdTokenClaims()
const tokenExp = tokenClaims !== undefined ? moment.unix(tokenClaims?.exp).format("YYYY-MM-DD HH:mm:ss") : moment()
const timeDiff = moment(tokenExp).diff(moment(), 'seconds')

if(await isAuthenticated() && timeDiff < 0) window.location.href = `${window.location.origin}/logout`

```

---

<div class="post-metadata">

**Author:** ![dawid.matuszczyk](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/dawid.matuszczyk/32/74550_2.png) [@dawid.matuszczyk](https://community.auth0.com/u/dawid.matuszczyk)\
**Post date:** [August 24, 2023, 12:20pm UTC](https://community.auth0.com/t/localstorage-require-log-in-after-feature-not-working/114216/3 "2023-08-24T12:20:00Z")

</div>

Hi @dally

Welcome back to the Auth0 Community!

Changing the `cacheLocation` to `localStorage` means that tokens persist even after the browser refreshes. However, while this approach provides some benefits, one downside is the token expiration handling since Auth0’s in-memory cache will respect the “Require log in after” setting. Still, when you switch to `localStorage` , it does not automatically handle that. Your method is a viable solution for the problem you’ve described. To fine-tune it you may want to consider background token renewal with the usage of `checkSession` method from the Auth0 SDK and Clear Auth0 Data as a good practice, you can do this by redirecting the user to Auth0’s logout URL.

If you found this post helpful or interesting, please give it a like 👍 Your interaction makes a difference. **Have a wonderful day!** 🌞

Dawid

* * *

[📹 _Prefer how-to videos instead of written docs? We’ve got you covered! Check out our OktaDev YouTube channel for those helpful resources!_](https://www.youtube.com/@OktaDev/videos)

---

<div class="post-metadata">

**Author:** ![dally](https://upload.wikimedia.org/wikipedia/commons/thumb/7/7c/User_font_awesome.svg/768px-User_font_awesome.svg.png) [@dally](https://community.auth0.com/u/dally)\
**Post date:** [August 24, 2023, 12:47pm UTC](https://community.auth0.com/t/localstorage-require-log-in-after-feature-not-working/114216/4 "2023-08-24T12:47:42Z")

</div>

Hi @dawid.matuszczyk, thank you for that information. I will looking into `checkSession` and see if it works better than my current solution.

---

<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:** [September 7, 2023, 12:48pm UTC](https://community.auth0.com/t/localstorage-require-log-in-after-feature-not-working/114216/5 "2023-09-07T12:48:28Z")

</div>

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