In my react project, I make an api call to my Node backend endpoint. In this endpoint I return a response with an x-auth-token header set. The code for the
response is shown below:
res.header('x-auth-token', token).send('User registered')
In react, I make an api call to this endpoint and I need to extract the x-auth-token and set the value of it in local storage. I try doing this however there is no header being sent with the response.
Here is a snippet of the code for the api call in react:
const response = await axios.post('http://localhost:5000/api/users/', {username: username, email: email, password: password})
console.log(response.headers.get('x-auth-token'))
In the console I get:
xhr.js:178 POST http://localhost:5000/api/users/ 400 (Bad Request)
And when I console log response.headers, in the console, I get this returned:
{content-length: "15", content-type: "text/html; charset=utf-8"}
content-length: "15"
content-type: "text/html; charset=utf-8"
__proto__: Object
Does anybody know the issue here? Thanks.