How to handle JWT token expiration in Angular 17?

  Рет қаралды 4,855

AyyazTech

AyyazTech

Күн бұрын

Пікірлер: 8
@thonyperez-d9y
@thonyperez-d9y 10 ай бұрын
Excelente trabalho meu amigo, o único que consegui esclarecer. Obrigado! Excellent work my friend, the only one I managed to clarify. Thanks!
@marchagreentree5590
@marchagreentree5590 7 ай бұрын
help me a lot, thank you so much. but little question, is this method work on every Algorithm of jwt?
@RBFraphael
@RBFraphael Жыл бұрын
I'm trying to replicate this behaviour on my project, but when I call return next(req) from the subscribe of the refresh token request, it doesn't "retry" the original request. How can I trigger a "retry" the original request with updated token?
@AyyazTech
@AyyazTech Жыл бұрын
Hey there! It sounds like you're working on implementing a token refresh mechanism in Angular. When you're trying to "retry" the original request after refreshing the token, you need to ensure that the new token is set in the headers of the original request before resending it. Here’s a quick approach: - Capture the Original Request: Before making the refresh token call, store the original request. - Refresh the Token: As you're already doing, refresh the token when needed. - Update the Original Request: Once you have the new token, update the original request’s headers with the new token. - Resend the Request: Finally, resend the original request with the updated token. It's a bit more complex than can be explained in a short comment, but this should give you a direction. If you'd like a detailed tutorial on this, let me know, and we might cover it in an upcoming video. Don’t forget to like, subscribe, and hit the bell icon for more updates! 🔔✨
@RBFraphael
@RBFraphael Жыл бұрын
@@AyyazTech Yes, you're right. I'm trying to implement a token refresh. My approach is, when the response of any request results in a 401 status code, I need to call my authService.refreshToken, which will return an HttpClient observable with token information. When it returns, I update my token on localStorage, then retry the original request. But when I call next(req) from inside the .subscribe() method of authService.refreshToken, it doesn't run. Checking the DevTools Network tab, I can see that Angular runs the main request, receives a 401 error, refreshes the token and stuck there.
@bulla1100
@bulla1100 9 ай бұрын
I can't access localStorage in the interceptor but I can anywhere else . "ERROR ReferenceError localStorage is not defined"
@cristi9483
@cristi9483 9 ай бұрын
I have the same issue. Did you manage to solve it?
@csirakdavid2326
@csirakdavid2326 7 ай бұрын
That is probably beacuse u are using SSR in your project. In order to acces localstorage wrap it with the built in isPlatformBrowser() method. Check Angular docs.
how to use JWT token in Angular 17
47:28
AyyazTech
Рет қаралды 11 М.
Farmer narrowly escapes tiger attack
00:20
CTV News
Рет қаралды 13 МЛН
99.9% IMPOSSIBLE
00:24
STORROR
Рет қаралды 21 МЛН
I thought one thing and the truth is something else 😂
00:34
عائلة ابو رعد Abo Raad family
Рет қаралды 17 МЛН
What type of pedestrian are you?😄 #tiktok #elsarca
00:28
Elsa Arca
Рет қаралды 43 МЛН
How to use @Input and @Output in Angular 17?
28:56
AyyazTech
Рет қаралды 8 М.
Beat Ronaldo, Win $1,000,000
22:45
MrBeast
Рет қаралды 111 МЛН
Session Vs JWT: The Differences You May Not Know!
7:00
ByteByteGo
Рет қаралды 272 М.
DHH discusses SQLite (and Stoicism)
54:00
Aaron Francis
Рет қаралды 101 М.
I only ever use *these* RxJS operators to code reactively
25:25
Joshua Morony
Рет қаралды 135 М.
Angular 19 is a BEAST of a release!
19:39
Maximilian Schwarzmüller
Рет қаралды 42 М.
How to make add to cart in Angular 17?
26:36
AyyazTech
Рет қаралды 6 М.
Angular Resource API - Everything You Have To Know (so far)
27:58
Decoded Frontend
Рет қаралды 14 М.
Dynamic Component in Angular (2024)
17:48
Decoded Frontend
Рет қаралды 26 М.
Farmer narrowly escapes tiger attack
00:20
CTV News
Рет қаралды 13 МЛН