-1

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.

Boopathi D
  • 361
  • 2
  • 21
  • What does the Express app in your question have to do with React? – Phil Mar 21 '22 at 02:21
  • @Phil Any guess why I cant access the response in Express – Boopathi D Mar 21 '22 at 02:25
  • Finally I found the problem. The session is not created. For session, Redis connection failed. I installed the redis in my local machine from https://redis.com/blog/redis-on-windows-10/ and https://stackoverflow.com/a/63698487/8280010 helps. – Boopathi D Mar 21 '22 at 08:02

1 Answers1

-1

check if your res.data is null. if so fix that and your problem is solved

Ayush Dubey
  • 112
  • 1
  • 7
  • Hi. I am getting the data in `console.log('response refresh_token', response.data.refresh_token);` when it is placed below `console.log('User login 1');` but cant get the data after `httpReq.session.isLogin = true;` – Boopathi D Mar 21 '22 at 02:33