【问题标题】:How can I return the response data from Auth0's API on my API?如何在我的 API 上返回来自 Auth0 的 API 的响应数据?
【发布时间】:2021-06-03 16:25:25
【问题描述】:

我正在使用 axios 调用 Auth0 的 API 来获取用户列表。我正在尝试使用我正在使用此语法的语法返回它们:

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

res.data 正在打印所需的结果。但我在 Postman 上得到并清空响应正文。

我也尝试了return res.data,只是超时。

我错过了什么?

【问题讨论】:

    标签: javascript axios auth0


    【解决方案1】:

    您在 Axios response 对象上调用 status 方法,而该方法应该在 Express response 对象上调用。

    您应该将 Auth0 API 响应命名为 res 以外的名称,以确保回调中的 res 引用 Express response 对象。或者更好地使用解构。而且您不必设置200 状态码,因为它是自动设置的。

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-12-04
      • 2017-09-14
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-06-12
      • 2017-01-16
      相关资源
      最近更新 更多