I have an application that backend
works with nodeJS
, in it I control the authentication process well, I have the problem in frontend
, I use token to authenticate and frontend
I save it in the LocalStorage
browser, but I don't know how to enter it in the header
and then in the backend get it in a middleware
.
Thanks in advance... Salu2s
According to the specification, the token must go in the header
Authorization
. In order not to make the process repetitive, you can make a utility function that prepares the requests:So you use it like this for example:
Obviously instead of fetch you can use libraries like Axios . In the backend you just have to write a middleware for your server that gets the header
Authorization
and checks if the token exists or is valid.