Flask - unable to get cookies Flask - unable to get cookies flask flask

Flask - unable to get cookies


According to the above, i assume you are using a frontend application based on any other framework and using libraries like axios, fetch, request, etc to hit API on the flask.

So, you might have missed out that you need to set a flag in request to allow sending cookies. Refer to below links to find ways to do it:

  1. Fetch API: https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API/Using_Fetch#Sending_a_request_with_credentials_included
    fetch('https://example.com', {      credentials: 'include'    });
  1. XMLHttpRequest
    var xhr = new XMLHttpRequest();    xhr.open('GET', 'http://example.com/', true);    xhr.withCredentials = true;    xhr.send(null);

Correct me, if doesn't solve the problem.


the following worked (as suggested in the answer from Dhruv Agarwal):

getToken(event) {    const {userId} = this.props    const options = {      url: `${process.env.REACT_APP_WEB_SERVICE_URL}/get_token/1`,      method: 'get',      headers: {        'Content-Type': 'application/json',        Authorization: `Bearer ${window.localStorage.authToken}`,      }    };    axios.defaults.withCredentials = true // <--------------------    return axios(options)    .then((res) => {      console.log('res.data.data)    })        .catch((error) => { console.log(error); });  };

I don't know what was missing in my Postman request, but now it's functional.