I am working on express app which has axios. In production it works fine. But in localhost I cant able to read the response data.
app.post('/login', function (httpReq, httpRes) {
console.log('httpReq.body',httpReq.body);
let creditial = { ...httpReq.body }
console.log('creditial', creditial);
httpReq.body && delete httpReq.body.login_type;
login(httpReq, httpRes, 'logIn', creditial && creditial.login_type)
})
login = (httpReq, httpRes, mode = 'logIn', login_type = null) => {
axios({
method: 'post',
url: `${oauth}`,
data: {
...httpReq.body,
grant_type: 'password',
client_id: process.env.client_id,
client_secret: process.env.client_secret
}
})
.then(response => {
console.log('User login 1');
console.log('response', response); // here I received the reponse.
httpReq.session.isLogin = true;
httpReq.session.access_token = response.data.access_token;
httpReq.session.refresh_token = response.data.refresh_token;
console.log('response refresh_token', response.data.refresh_token); // here I cant get the response.data
....
....
....
....
})
.catch(function (error) {
if (error.response) {
let data = { ...error.response.data }
data.statusText = 'OK'
httpRes.status(error.response.status)
httpRes.json(data)
}
})
}
Any help would be much appreciated. I am just beginner in node.