I am using ExpressJS as backend and Reactjs in frontend. I am trying to use session in app.post but it does not work when i do not include credentials whenever i include credentials i get the following error even after setting all Headers. (Note: data is in json)
Frontend :
Axios.post('http://localhost:5002/api/me/create', data ,
{
withCredentials: true,
headers: { 'content-type': 'application/json' },
})
Backend :
app.post('/api/me/create', function (req, res) {
res.setHeader('Access-Control-Allow-Origin', 'http://localhost:5000');
res.setHeader('Access-Control-Allow-Credentials', 'true');
res.setHeader('Access-Control-Allow-Headers', 'content-type');
res.setHeader('Content-Type', 'application/json');
console.log(req.session.uuid);
req.session.uuid = 5;
}
Error :
Access to XMLHttpRequest at 'http://localhost:5002/api/me/create' from origin 'http://localhost:5000' has been blocked by CORS policy: Response to preflight request doesn't pass access control check: The value of the 'Access-Control-Allow-Origin' header in the response must not be the wildcard '*' when the request's credentials mode is 'include'. The credentials mode of requests initiated by the XMLHttpRequest is controlled by the withCredentials attribute.