Reputation: 471
I have an Angular 10 Universal project that uses JWT retrieved from localhost in order to authenticate requests for private routes.
I currently use this project for the authentication process: https://www.npmjs.com/package/@auth0/angular-jwt
The problem I believe I am facing with Angular Universal is that when rendering pages that require authentication my requests are unable to retrieve the JWT token from localStorage. Note, this is what I think the issue is because I get a 401 unauthorized on these requests and have done some reading.
Is there any way to authenticate these requests using the JWT token that is returned when a user logs in to the website?
Backend is .Net Core 2.1
Upvotes: 1
Views: 1346
Reputation: 36
Can you save JWT to cookies after receiving it? In that case JWT will be sent along with the request, so it can be processed on server side. Also, i think it would be nice to set this cookie with secure flag, so it can't be accessed from js in case of xss vulnerability (so it cannot be sent to 3rd party service)
Upvotes: 1