I'm using a node.js express back-end with passport-local as the authentication strategy. I'm using react as the front-end, and when I use a fetch request to log in, it works fine. However, the 'Set-Cookie' header in the response doesn't set a cookie in my browser, and when I try to access an authentication protected route on my back-end I get a '401' error.
Login request code (works fine and returns a response with 'Set-Cookie' header):
fetch('http://localhost:3001/login', {
method: 'post',
mode: 'cors',
headers: {
'content-type': 'application/json',
'access-control-allow-origin': 'localhost:3000'
},
body: JSON.stringify({ email, password })
})
Profile Info Request (doesn't work):
fetch('http://localhost:3001/profile-info', {
method: 'get',
mode: 'cors',
withCredentials: 'true',
headers: {
'content-type': 'application/json',
'access-control-allow-origin': 'http://localhost:3000'
}
})