0
votes

Any idea on how to implement cookie auth in Angular 6? I have tried using AuthGuard but I'm not able to check if the user is authenticated or not because the cookie is HttpOnly so I can't access its content. I need this to protect some routes.

Thanks!!!

1
This is a quite good tutorial: medium.com/@ryanchenkie_40935/… - Luud van Keulen
Thanks for your response, but the problem is that It must be done using cookies, I can't use jwt. - Warthaxx
Cookies is just a way to store information in the browser. You will need some form of tokens. What do you store in the cookies? Jwt uses cookies aswell. - Luud van Keulen
You won't be able to leverage an Http-Only cookie to do an authentication check on the client-side, however you can pass this cookie to an API endpoint to determine that and pass back a response which you can use in your route guard. - Brandon
@Brandon I think I'll try what you say, but how do I send the cookie to the server? Adding withCredentials: true I suppose. - Warthaxx

1 Answers

-1
votes

with JWT you should save the token, you must kepp the key in the cookie.