简体   繁体   中英

How can I return the response data from Auth0's API on my API?

I'm calling Auth0's API with axios to fetch a list of users. I'm trying to return them using the syntax that I'm using this syntax:

.then(res => {
  console.log(res.data) // Prints the deired result
  return res.status(200).json(res.data);
})

res.data is printing the desired result. But I'm getting and empty response body on Postman.

I also tried return res.data , only to get a timeout.

What am I missing?

You're calling the status method on the Axios response object when it should be called on the Express response object.

You should name the Auth0 API response something other than res to make sure res inside the callback refers to the Express response object. Or better use destructuring. And you don't have to set the 200 status code since it is set automatically.

.then(({ data }) => res.json(data))

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM