---
title: "Comment by rasd on \"React & JWT Authentication - the right way!\" | Hashnode"
description: "What happens when the token should be refreshed and you have multiple requests that are being sent at that time? Won&#39;t all the request get 401?"
url: "https://hashnode.com/posts/react-and-jwt-authentication-the-right-way/5f7332311d7a870a345b9db2/comment/5f744280e46f1616184269a2"
---

[Discussion](https://hashnode.com/posts/react-and-jwt-authentication-the-right-way/5f7332311d7a870a345b9db2)

Comment [React & JWT Authentication - the right way!](https://hashnode.com/posts/react-and-jwt-authentication-the-right-way/5f7332311d7a870a345b9db2)

[rasd](https://hashnode.com/@rasd)

[Sep 30, 2020](https://hashnode.com/posts/react-and-jwt-authentication-the-right-way/5f7332311d7a870a345b9db2/comment/5f744280e46f1616184269a2)

What happens when the token should be refreshed and you have multiple requests that are being sent at that time? Won't all the request get 401?

[Gal Malachi](https://hashnode.com/@galm)

[Sep 30, 2020](https://hashnode.com/posts/react-and-jwt-authentication-the-right-way/5f7332311d7a870a345b9db2/comment/5f744280e46f1616184269a2#reply-5f74458b5defaf19d6aada50)

Yes, you are right. To prevent that we should send the refresh-token request few seconds before it expires. I will add that in.

[rasd](https://hashnode.com/@rasd)

[Sep 30, 2020](https://hashnode.com/posts/react-and-jwt-authentication-the-right-way/5f7332311d7a870a345b9db2/comment/5f744280e46f1616184269a2#reply-5f7451b2b9c62319b5670fe0)

[Gal Malachi](https://hashnode.com/@gal1419) I usually have a retry logic. So if it happens and a request is sent and has a 401 it will get the token and add it to retry list using the promise. If requests are being sent after sending the request to get the token but before setting it, I add it to the retry list. So using the request(the ones that should be sent) and response(the ones that got 401) interceptors I will add the request to the retry list and send them when the token has been refreshed using the promises(replace the old token). I use a timer to refresh the tokens but also have the retry logic attached to that. The oauth2 implementation I have worked with will not provide new tokens unless the old ones are expired, even if it would I think there are scenarios where the token would be invalid for current request. But even with this implementation I am unsure if this is a good solution, I feel there could be other scenarios in which the token would not be used/refreshed properly.

[Gal Malachi](https://hashnode.com/@galm)

[Sep 30, 2020](https://hashnode.com/posts/react-and-jwt-authentication-the-right-way/5f7332311d7a870a345b9db2/comment/5f744280e46f1616184269a2#reply-5f74624d5defaf19d6aadb95)

[rasd](https://hashnode.com/@rasd) sounds like a complete solution! I thought about setting a retry logic, but I didn’t want to complicate stuff since this post is very long as is. However, I do believe that calling the refresh endpoint few seconds before the token expires should cover 99% of the cases.
