I am trying to learn Backend/Frontend development and one of my challenges so far has been to understand JWT authentication. But the more I research this topic the more confused I get.
I have seen that storing the JWT token on the frontend's localstorage is a bad thing and I should be doing it via HttpOnly cookies. However for me to use the token on frontend I would need to access it from the cookie, which I can't because it's HttpOnly, so I figured I would just make calls to the backend while having the cookie and the backend would send the data back already authorized, however I was then told that the token should be passed in the authentication header and not in the cookie.
So I wanted to ask, what is the correct way to handle this situation?
Do I query the backend with the cookie, get the token back, store the token in memory then quary the backend again for data using the token in the authentication header?
This sounds a bit counter productive, no?
I really want to learn this topic and learn what is the correct way to secure the login.