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:
fetch('https://example.com', { credentials: 'include' });
- 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.