Refreshing Tokens With Axios Interceptors

Refreshing Tokens With Axios Interceptors

Dennis Ivy

2 года назад

87,508 Просмотров

Ссылки и html тэги не поддерживаются


Комментарии:

Joao Arthur Bandeira
Joao Arthur Bandeira - 14.07.2023 17:02

Hey Dennis! Excellent tutorial, as always!

Can you also show us how to do registration and also how a logged in authenticated user can do post requests to create/update notes?

Cheers, bro!

Ответить
Paulo Bruno
Paulo Bruno - 09.07.2023 05:52

Thank youuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuu

Ответить
Kipruto Barno
Kipruto Barno - 28.06.2023 00:44

Great stuff!

Ответить
Anderson Omorogbe
Anderson Omorogbe - 26.05.2023 02:16

This is legit the best video I found on this topic. Also, we use the same vscode theme.. lol

Ответить
Anthony Donovan
Anthony Donovan - 26.04.2023 14:18

the api should really be in the dependency array of the useeffect, but that would then cause an infinite re-render loop

Ответить
Emilio Carrino
Emilio Carrino - 19.04.2023 12:08

this would create a race condition when multiple requests starts in parallel. Example: Request A has expired token -> refresh token POST request starts to renew it -> While the refresh request is still going Request B enters the chat -> has expired token -> starts a new Refresh Token Request. This creates a race condition. A lock/queue mechanism MUST be implemented to call this a real solution. I'm sorry but this tutorial is actually misleading.

Ответить
Harit Patel
Harit Patel - 17.04.2023 09:56

Amazing video, learned a lot...

Ответить
supersecretninjame
supersecretninjame - 03.04.2023 15:19

i think the reason that people check in in the response rather than pre-request is that it is a more general approach that works on a wider range of back-end applications where you are not 100% sure of how the back-end is set up and how it validates the tokens. For example if there is something other than time that makes the token invalid, you renew the token as a standard procedure upon request fail regardless of why that is. However, if you have full control over the back-end and know all possible outcomes (aka you know that you need to check the exp time) I think intercepting before the request makes more much more sense.

Ответить
Spencer Mitton
Spencer Mitton - 15.03.2023 00:54

Great video, I would point out though that refreshing the auth token in the useEffect is inefficient. IMO it would be better to store the expiration time of the token, and then whenever you need to access the API you check the expiration time, and update the access token if necessary.

Ответить
Sarbottam Chatterjee
Sarbottam Chatterjee - 23.02.2023 18:11

Forgive me if I am wrong, but shouldnot we check the expiry of the refresh token too before requesting a new access and refresh token? Just in case the user hasn't logged in for more than 90 days, so we simply logout the user.

Ответить
Betoml5
Betoml5 - 11.02.2023 21:36

Amazingg!!! Thanks for this, i have been trying to learn how to manage the auth flow and now i know how. Thank u soo muchh. Saludos desde Mexico

Ответить
Tech
Tech - 05.12.2022 11:10

Nice explanation man. Your side tangents really helped us understand the entire context.

Ответить
Code With Project
Code With Project - 30.10.2022 18:42

i agree
i dont know alot of people are trying to refresh token at frontend stack.
its done with a one middleware .

Ответить
mysterious billionaire
mysterious billionaire - 01.10.2022 05:07

Anything on social login please?

Ответить
Dani Asecas
Dani Asecas - 26.08.2022 23:22

Hello everyone, first of all I'm sorry for my bad English I'm tall and I've worked with the translator xd
Well, I think that in react in the updateToken function in the first conditional after creating data (yes, the one with status === 200) the resfresh token should be added in data, at least if I don't add it, the resfresh doesn't work since it needs to. Greetings and good night to all coders ;)

Ответить
Kleidi Lamka
Kleidi Lamka - 15.08.2022 19:27

Great tutorial. Thank you for the quality content!

Ответить
Stammering Programmer
Stammering Programmer - 12.08.2022 13:38

That's my boy, I started following u since last year. You're awesome

Ответить
StickMan1316
StickMan1316 - 30.07.2022 02:01

I'm having an issue when I first login and my Authtoken doesn't appear. because of this I would have to refresh the page then it's there along with other backEnd data. How do I fix this? I've google this issue and couldn't find any solution.

Ответить
Zahra Reyhanian
Zahra Reyhanian - 16.07.2022 09:00

Thak you for this awesome video.

Ответить