У меня есть следующий код в fe:
getTasks = () => {
axios.get("http://127.0.0.1:3000/api/getTasks", {
withCredentials: true
}).then(response => {
console.log(response)
})
}
и этот код будет:
var app = express();
app.use(bodyParser.urlencoded({ extended: true }));
app.use(bodyParser.json());
app.use(cookieParser());
app.use(function (req, res, next) {
res.header('Access-Control-Allow-Origin', req.header('origin'));
res.header("Access-Control-Allow-Headers", "Origin, X-Requested-With, Content-Type, Accept");
res.header("Access-Control-Allow-Credentials: true");
next();
});
, когда пользователь входит в систему и запрашивает getTasks (), я получаю эту ошибку:
Access to XMLHttpRequest at 'http://127.0.0.1:3000/api/getTasks' from origin 'http://localhost:3002' has been blocked by CORS policy: The value of the 'Access-Control-Allow-Credentials' header in the response is '' which must be 'true' when the request's credentials mode is 'include'. The credentials mode of requests initiated by the XMLHttpRequest is controlled by the withCredentials attribute.