I had issues with token data and changed the property names at Savetoken function jwtToken to JWTToken, and refreshToken to RefreshToken. jwtToken and refreshToken were undefined.
Based on your code user cannot logout untill he hit logout button right ..but if we want when user actively working in this case I need refresh token if user not working and token expired then I need he should logout and relogin ...please suggest me
Hello! Thx for this great example! But.... if you wanna receive the refresh token and the server response 401, too (is expired, too as example) nothing happened. The Interceptor hangs and the error will not be handled.
cant we avoid printing the 401 unauthroized in console, we are calling handlerefreshing token it is working good, but when the token is expired it will check status 401 and call refresh method. when token is expired, it is showing 401 in console
im getting list data by using intercepotrs refresh token method,(after expiration the data is getting) in console, it showing the request is error with 401 status. why it is giving in console, when it is working . is it a bug ??
Switchmap is one of rxjs operators for access observable inside the observanle for more details refer this link ruclips.net/video/FVgaacYNoy0/видео.html
1,Can you share the error message? 2, when you are facing issue while running (or) after deployment? 3,Possible reason when 2 services depending on each other then this will show error. Solving this error need to create separate service
Hello, I copied your code as you have it and I am using Angular 14. On the refresh I am receiving this error: pipe is not a function at this line of code: return authservice.GenerateRefreshToken().pipe(. Did something change between Angular 13 and 14? Here is my code: handleRefrehToken(request: HttpRequest, next: HttpHandler) { let authRequest = request; return this.authService.GetRefreshToken().pipe( switchMap((data: any) => { this.authService.SaveTokens(data); //authRequest = this.AddTokenheader(request); return next.handle(this.AddTokenheader(request)); }), catchError(errordata =>{ console.log('logout') this.store.dispatch(logoutAction()); return throwError(()=>errordata); }) ); I have Angular version 14.2.3 and "typescript": "~4.8.3" thank you
Very nice and helpful can you explain how to handle cors error in production
Will upload soon
I had issues with token data and changed the property names at Savetoken function jwtToken to JWTToken, and refreshToken to RefreshToken. jwtToken and refreshToken were undefined.
It's case sensitive so check what response you received from api.... Change it accordingly
Based on your code user cannot logout untill he hit logout button right ..but if we want when user actively working in this case I need refresh token if user not working and token expired then I need he should logout and relogin ...please suggest me
In interceptor i added calling refresh token logic... Then you can directly do log out also you can give some alert like current session expired
@@NihiraTechiees thank you sir
Hello! Thx for this great example! But.... if you wanna receive the refresh token and the server response 401, too (is expired, too as example) nothing happened. The Interceptor hangs and the error will not be handled.
For error handling follow this video ruclips.net/video/aiknsMjF1n0/видео.html
cant we avoid printing the 401 unauthroized in console, we are calling handlerefreshing token it is working good, but when the token is expired it will check status 401 and call refresh method. when token is expired, it is showing 401 in console
Please share the code snippets to my mail
Same here, if you can share the solution please
im getting list data by using intercepotrs refresh token method,(after expiration the data is getting) in console, it showing the request is error with 401 status. why it is giving in console, when it is working . is it a bug
??
Did you missed any step. Please verify it
is it normal that in developers tool, you will see 401 error, even you have intercepted 401?
May be previous exception not cleared
Can you show in the video the dev tools is not logging any 401 in console? Tyia
What is the use of switchMap()?
Switchmap is one of rxjs operators for access observable inside the observanle for more details refer this link ruclips.net/video/FVgaacYNoy0/видео.html
In getting Circular dependency in DI error ):
1,Can you share the error message?
2, when you are facing issue while running (or) after deployment?
3,Possible reason when 2 services depending on each other then this will show error.
Solving this error need to create separate service
This guy really needs to work on his accent and explanation, he is really bad explaining concepts in a comprehensible manner
I happy to have freelancer like you for doing free quality check....good job brother 👍
Hello, I copied your code as you have it and I am using Angular 14. On the refresh I am receiving this error: pipe is not a function at this line of code: return authservice.GenerateRefreshToken().pipe(. Did something change between Angular 13 and 14? Here is my code:
handleRefrehToken(request: HttpRequest, next: HttpHandler) {
let authRequest = request;
return this.authService.GetRefreshToken().pipe(
switchMap((data: any) => {
this.authService.SaveTokens(data);
//authRequest = this.AddTokenheader(request);
return next.handle(this.AddTokenheader(request));
}),
catchError(errordata =>{
console.log('logout')
this.store.dispatch(logoutAction());
return throwError(()=>errordata);
})
);
I have Angular version 14.2.3 and "typescript": "~4.8.3"
thank you
Pipe is a operator from rxjs. Please check do you have the package
@@NihiraTechiees "rxjs": "~7.4.0",
Please send me the file to my email
please send me full code of interceptor
Check in description