# Custom storage tokenManager setItem fires more often than needed

**URL:** <https://devforum.okta.com/t/custom-storage-tokenmanager-setitem-fires-more-often-than-needed/14556>\
**Category:** Questions\
**Created:** [June 4, 2021, 7:31pm UTC](https://devforum.okta.com/t/custom-storage-tokenmanager-setitem-fires-more-often-than-needed/14556 "2021-06-04T19:31:52Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![DavidLozzi](https://sea1.discourse-cdn.com/oktadev/user_avatar/devforum.okta.com/davidlozzi/32/1974_2.png) [@DavidLozzi](https://devforum.okta.com/u/DavidLozzi)\
**Post date:** [June 4, 2021, 7:31pm UTC](https://devforum.okta.com/t/custom-storage-tokenmanager-setitem-fires-more-often-than-needed/14556/1 "2021-06-04T19:31:52Z")

</div>

We are using a custom storage provider in our `tokenManager`, parsing some cookies ourselves. In our `setItem` method for the token manager, we are also generating a randomly created ID for another use case. This ID appears to change throughout the day causing us some issues. This leads me to believe this `setItem` function gets called more than when the user first logs in.

When does `setItem` get called? Why is it happening more than once? Is there anyway within `setItem` to know what changed or why so we can handle changes correctly?

---

<div class="post-metadata">

**Author:** ![Cale](https://sea1.discourse-cdn.com/oktadev/user_avatar/devforum.okta.com/cale/32/2496_2.png) [@Cale](https://devforum.okta.com/u/Cale)\
**Post date:** [June 4, 2021, 7:44pm UTC](https://devforum.okta.com/t/custom-storage-tokenmanager-setitem-fires-more-often-than-needed/14556/2 "2021-06-04T19:44:34Z")

</div>

Hi there. Possibly this could be happening due to autorenew. See the docs here:

> **[okta/okta-auth-js - autoRenew](https://github.com/okta/okta-auth-js#autorenew)**
>
> The official js wrapper around Okta's auth API. Contribute to okta/okta-auth-js development by creating an account on GitHub.

_By default, the `tokenManager` will attempt to renew tokens before they expire. If you wish to manually control token renewal, set `autoRenew` to false to disable this feature. You can listen to [`expired`](https://github.com/okta/okta-auth-js#tokenmanageronevent-callback-context) events to know when the token has expired._

So potentially, unless you set autoRenew to false, it could be running and causing that setItem method to fire

---

<div class="post-metadata">

**Author:** ![DavidLozzi](https://sea1.discourse-cdn.com/oktadev/user_avatar/devforum.okta.com/davidlozzi/32/1974_2.png) [@DavidLozzi](https://devforum.okta.com/u/DavidLozzi)\
**Post date:** [June 4, 2021, 7:52pm UTC](https://devforum.okta.com/t/custom-storage-tokenmanager-setitem-fires-more-often-than-needed/14556/3 "2021-06-04T19:52:33Z")

</div>

thanks for that. it looks like it attempts autorenew 30 seconds before expiration, we have a 24 hour expiration on our access tokens… ah ha, it appears the id token was renewed when the `setItem` ran again, which makes sense… ok, I think we can determine if the access token changes by comparing the incoming value to what’s in our cookie.

Do you know if when the ID token is renewing, do we get the access token as well? or will we only get the id token value? (i’ll have to find out the hard way here if I have to debug)

---

<div class="post-metadata">

**Author:** ![Cale](https://sea1.discourse-cdn.com/oktadev/user_avatar/devforum.okta.com/cale/32/2496_2.png) [@Cale](https://devforum.okta.com/u/Cale)\
**Post date:** [June 4, 2021, 7:57pm UTC](https://devforum.okta.com/t/custom-storage-tokenmanager-setitem-fires-more-often-than-needed/14556/4 "2021-06-04T19:57:37Z")

</div>

No problem! And at the 1 hour mark when it renews the ID token, it should only renew the ID token, not access. (Unless of course you set the access token to a 1 hour expiry)

---

<div class="post-metadata">

**Author:** ![system](https://global.discourse-cdn.com/oktadev/original/1X/589c4c5f80de422d01f47cee7185a7fb8227835c.png) [@system](https://devforum.okta.com/u/system)\
**Post date:** [April 25, 2022, 6:09pm UTC](https://devforum.okta.com/t/custom-storage-tokenmanager-setitem-fires-more-often-than-needed/14556/5 "2022-04-25T18:09:53Z")

</div>

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