# How to fix if token is expired

**URL:** <https://community.auth0.com/t/how-to-fix-if-token-is-expired/138637>\
**Category:** Get Help\
**Tags:** apis, application\
**Created:** [July 11, 2024, 10:30am UTC](https://community.auth0.com/t/how-to-fix-if-token-is-expired/138637 "2024-07-11T10:30:09Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![sanjay2](https://upload.wikimedia.org/wikipedia/commons/thumb/7/7c/User_font_awesome.svg/768px-User_font_awesome.svg.png) [@sanjay2](https://community.auth0.com/u/sanjay2)\
**Post date:** [July 11, 2024, 10:30am UTC](https://community.auth0.com/t/how-to-fix-if-token-is-expired/138637/1 "2024-07-11T10:30:09Z")

</div>

Ready to post? 🔍 First, try searching for your answer.  
We have the application frontend as react and backend as flask api. We have configured both using Auth0 which means we have integrated in react using Auth0 Provider as a token automatically creates.

For API: we are validating the token which coming from frontend, if it is valid token then we are returning success but the problem here is how to handle if expired token is coming from frontend, as standard process at api, it will reject.

But we don’t want to reject the token, we want to extend same token lifespan in same request, I see refreshtoken will do that but how to handle if token is expired between the requests. Please help.

\<Auth0  
domain=“”  
clientId=“”  
authorizationParams={{  
redirect\_uri: window.location.origin,  
audience: “”,  
scope : “openid email profile offline\_access”  
}}  
useRefreshTokens={true}  
cacheLocation=“localstorage”  
useRefreshTokensFallback={true}  
\>  
{children}

using above code, token will refresh, but how to handle if the expired token is already passed to api, it should not throw token is expired. Please help on this.

---

<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:** [July 11, 2024, 5:42pm UTC](https://community.auth0.com/t/how-to-fix-if-token-is-expired/138637/3 "2024-07-11T17:42:42Z")

</div>

Hey there @sanjay2 welcome to the community!

> [@sanjay2](#):
>
> For API: we are validating the token which coming from frontend, if it is valid token then we are returning success but the problem here is how to handle if expired token is coming from frontend, as standard process at api, it will reject.
> 
> But we don’t want to reject the token, we want to extend same token lifespan in same request, I see refreshtoken will do that but how to handle if token is expired between the requests. Please help.

How often are you getting expired tokens at your API? Assuming refresh tokens/silent auth are being utilized correctly, this should rarely ever occur. In the case this does occur (think absolute expiration of refresh token) the user will need re-authenticate. This will need to be done client-side - There is no way to handle this at your API.

---

<div class="post-metadata">

**Author:** ![sanjay2](https://upload.wikimedia.org/wikipedia/commons/thumb/7/7c/User_font_awesome.svg/768px-User_font_awesome.svg.png) [@sanjay2](https://community.auth0.com/u/sanjay2)\
**Post date:** [July 17, 2024, 7:26am UTC](https://community.auth0.com/t/how-to-fix-if-token-is-expired/138637/4 "2024-07-17T07:26:52Z")

</div>

Thank you so much for responding, I realized that `getAccessTokenSilently` will always gives latest token, which helped us to fix the problem.

---

<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:** [July 17, 2024, 4:38pm UTC](https://community.auth0.com/t/how-to-fix-if-token-is-expired/138637/5 "2024-07-17T16:38:36Z")

</div>

That’s great - Glad you were able to resolve the issue 🙂

---

<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:** [July 31, 2024, 4:39pm UTC](https://community.auth0.com/t/how-to-fix-if-token-is-expired/138637/6 "2024-07-31T16:39:25Z")

</div>

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