Axios / JWT post 401 (Mac OS and iOS only) “rest_forbidden”

落爺英雄遲暮 提交于 2020-06-01 05:09:38

问题


I'm working on a Vue app that uses Axios and Wordpress JWT Auth for authentication. Recently I started getting this 401 when trying to post (100% of the time) ...but... only on Mac OS X and iOS.

Can you point me in the right direction as to how to troubleshoot this? The error object in Chrome console network is this:

{"code":"rest_forbidden","message":"Sorry, you are not allowed to do that.","data":{"status":401}}

My post looks like this:

https://wordpressroot.ourdomain.com/wp-json/jwt-auth/v1/folder/transfer {location_id: "rec4ttKVWJCDr8v", items: Array(1)}

axios localClient:

import axios from "axios";
import environment from "@/environments/environment";
import state from "../store";
import router from "../router";

const userData = JSON.parse(localStorage.getItem("userData"));

let instance = {};

if (userData) {
  instance = axios.create({
    baseURL: environment.CUSTOM_BASE_URL,
    headers: { Authorization: `Bearer ${userData.token}` }
  });
} else {
  instance = axios.create({
    baseURL: environment.CUSTOM_BASE_URL
  });
}

instance.interceptors.request.use(
  config => {
    state.commit("setNetworkStatus", true);
    return config;
  },
  error => {
    return Promise.reject(error);
  }
);

instance.interceptors.response.use(
  response => {
    state.commit("setNetworkStatus", false);
    return response;
  },
  error => {
    if ([401, 403].includes(error.response.status)) {
      console.log(error);
      state.commit("delUserData");
      router.push("/login");
    }
    return Promise.reject(error);
  }
);

export default {
  get(path) {
    return instance.get(instance.defaults.baseURL + path);
  },
  post(path, params) {
    console.log(instance.defaults.baseURL + path, params);
    return instance.post(instance.defaults.baseURL + path, params);
  },
  put(path, params) {
    return instance.put(instance.defaults.baseURL + path, params);
  },
  delete(path, params) {
    return instance.delete(instance.defaults.baseURL + path, params);
  }
};

来源:https://stackoverflow.com/questions/62110323/axios-jwt-post-401-mac-os-and-ios-only-rest-forbidden

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