简体   繁体   English

如何在我的 API 上返回来自 Auth0 的 API 的响应数据?

[英]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.我正在调用 Auth0 的 API 和 axios 来获取用户列表。 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. res.data 正在打印所需的结果。 But I'm getting and empty response body on Postman.但我在 Postman 上得到并清空响应正文。

I also tried return res.data , only to get a timeout.我也试过return res.data ,只是为了得到一个超时。

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.你在 Axios响应object 上调用status方法,而它应该在 Express响应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.您应该将 Auth0 API 响应命名为res以外的其他名称,以确保回调中的res指的是 Express响应object。 Or better use destructuring.或者更好地使用解构。 And you don't have to set the 200 status code since it is set automatically.而且您不必设置200状态代码,因为它是自动设置的。

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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