Fetch Cross-domain POST reports 401 Unauthorized

export const login = accesstoken => dispatch => {
  return fetch("https://cnodejs.org/api/v1/accesstoken", {
    method: "POST",
    body: JSON.stringify({ accesstoken })
  }).then(res => {
    if (res.ok) {
      return res.json()
    } else {
      return Promise.reject(res.statusText)
    }
  }).then(({
    loginname
  }) => Promise.resolve(loginname))
}

as above, the native Fetch interface of the browser is used, but because the cross-domain POST request is involved, the OPTIONS request is not sent in advance, so 401 is returned directly. Is there any better solution?

Feb.26,2021

  preflight request . 

Menu