diff --git a/src/pages/src/http/fetch/index.ts b/src/pages/src/http/fetch/index.ts index da958c722..68d4fb681 100644 --- a/src/pages/src/http/fetch/index.ts +++ b/src/pages/src/http/fetch/index.ts @@ -46,7 +46,6 @@ const axiosInstance = axios.create({ xsrfCookieName: window.CSRF_COOKIE_NAME, xsrfHeaderName: 'X-CSRFToken', headers: { - 'X-CSRFToken': Cookies.get(window.CSRF_COOKIE_NAME), 'x-requested-with': 'XMLHttpRequest', }, }); @@ -111,6 +110,14 @@ const handleReject = (error: AxiosError, config: Record) => { return Promise.reject(error); }; +// 更新axios实例的cookie +function updateAxiosInstance() { + const csrfToken = Cookies.get(window.CSRF_COOKIE_NAME); + if (csrfToken !== undefined) { + axiosInstance.defaults.headers.common['X-CSRFToken'] = csrfToken; + } +} + methods.forEach((method) => { Object.defineProperty(http, method, { get() { @@ -122,6 +129,8 @@ methods.forEach((method) => { ? axiosInstance[method as Methods]>(fetchURL, payload, config) : axiosInstance[method as Methods]>(fetchURL, config); + updateAxiosInstance(); + return axiosRequest .then(response => handleResponse({ response, diff --git a/src/pages/src/views/setting/LoginSetting.vue b/src/pages/src/views/setting/LoginSetting.vue index 4f1998ccd..b39d9fb3f 100644 --- a/src/pages/src/views/setting/LoginSetting.vue +++ b/src/pages/src/views/setting/LoginSetting.vue @@ -10,7 +10,9 @@ class="login-item" v-for="(item, index) in idpsPlugins" :key="index"> -