# How do I check cached token expiry in an Auth0 Rule?

**URL:** <https://community.auth0.com/t/how-do-i-check-cached-token-expiry-in-an-auth0-rule/88971>\
**Category:** Get Help\
**Tags:** jwt, expiration, rule\
**Created:** [August 18, 2022, 2:13pm UTC](https://community.auth0.com/t/how-do-i-check-cached-token-expiry-in-an-auth0-rule/88971 "2022-08-18T14:13:35Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![jgleason](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/jgleason/32/25904_2.png) [@jgleason](https://community.auth0.com/u/jgleason)\
**Post date:** [August 18, 2022, 2:13pm UTC](https://community.auth0.com/t/how-do-i-check-cached-token-expiry-in-an-auth0-rule/88971/1 "2022-08-18T14:13:35Z")

</div>

I have a rule that calls a service using a M2M token. I want to cache the token in the rule and then refresh it when it has expired. What would the proper way to decode and check the expiry be? JWT-Decode?

---

<div class="post-metadata">

**Author:** ![ty.frith](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/ty.frith/32/58484_2.png) [@ty.frith](https://community.auth0.com/u/ty.frith)\
**Post date:** [September 1, 2022, 10:59pm UTC](https://community.auth0.com/t/how-do-i-check-cached-token-expiry-in-an-auth0-rule/88971/3 "2022-09-01T22:59:18Z")

</div>

Hey there @jgleason sorry for the delayed response!

Yes, [jwt-decode](https://www.npmjs.com/package/jwt-decode) will do the trick and I’ve seen this used before 🙂

---

<div class="post-metadata">

**Author:** ![ty.frith](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/ty.frith/32/58484_2.png) [@ty.frith](https://community.auth0.com/u/ty.frith)\
**Post date:** [September 16, 2022, 10:59pm UTC](https://community.auth0.com/t/how-do-i-check-cached-token-expiry-in-an-auth0-rule/88971/4 "2022-09-16T22:59:49Z")

</div>

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