React app throws 401 error when accessed through safari, but not otherwise

假如想象 提交于 2019-12-13 03:46:47

问题


I have a react app hosted in an s3 bucket behind a cloudfront distribution. This talks to a django server. Login works correctly on all browsers (confirmation that credentials are correct, and no fundamental connection issues). Once logged in, the app redirects to a page that does a simple GET request via fetch (to a url that requires authentication). This works successfully on all browsers on desktop (macos) except safari, which gets a 401 unauthorised error. Similarly, I get a 401 unauthorised error on every browser on iOS.

I've tried flushing the DNS of the mac, to no avail. I'm totally stumped. If it didn't work at all, that would be fine, but working everywhere apart from safari?

fetch code:

  componentDidMount() {
    fetch(`${apiRoot}/info`, {
      method: "GET",
      headers: {
        Accept: "application/json",
        "Content-Type": "application/json",
        Authorization: `Token ${this.props.auth.token}`
      }
    })
      .then(response => response.json())
      .then(data => {
        this.setState({
          Name: data.name,
          Email: data.email
        });
      });
  }

来源:https://stackoverflow.com/questions/54190579/react-app-throws-401-error-when-accessed-through-safari-but-not-otherwise

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!