【问题标题】:Auth0 axios.post with token Internal Server Error 500Auth0 axios.post 与令牌内部服务器错误 500
【发布时间】:2021-03-23 08:06:06
【问题描述】:

我正在尝试使用来自 Auth0 的令牌标头通过 axios.post 发布。我收到以下错误

代码

const [AccessToken, setAccessToken] = useState(null);

useEffect(() => {
    (async () => {
      const token = await getAccessTokenSilently({
        audience: 'api.paintit',
        scope: 'read:posts',
      });
      setAccessToken(token);
    })();
  }, []);

axios.post(
      url,
      {data:{
        data
      }
      },
      {
        headers: {
          'Authorization': `Bearer ${AccessToken}` 
        }
      }
    ).then((response) => {
        console.log(response);
      })
      .catch((error) => {
        console.log(error.response);
      });

我需要将标题添加到 axios 以供登录用户使用。这适用于获取请求和发布请求,我收到了该错误。 请帮助我将非常感激。

【问题讨论】:

  • 错误来自服务器,而您正在显示客户端代码。您需要在问题中包含服务器代码和错误日志
  • 我没有在前端做错?
  • 在服务器 HttpError: child "userId" 失败,因为 ["userId" is required]

标签: javascript reactjs oauth axios


【解决方案1】:
axios.post(
      url,
        data,
      {
        headers: {
          'Authorization': `Bearer ${AccessToken}` 
        }
      }
    ).then((response) => {
        console.log(response);
      })
      .catch((error) => {
        console.log(error.response);
      });

我添加的数据有误

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2022-01-22
    • 2019-07-16
    • 2014-04-02
    • 1970-01-01
    • 1970-01-01
    • 2019-01-17
    • 2011-10-17
    • 2010-11-15
    相关资源
    最近更新 更多