diff --git a/resources/js/controllers/html_load_controller.js b/resources/js/controllers/html_load_controller.js index 3a9392d9c..30061526a 100644 --- a/resources/js/controllers/html_load_controller.js +++ b/resources/js/controllers/html_load_controller.js @@ -41,8 +41,21 @@ export default class extends ApplicationController { window.axios.defaults.headers.common['X-CSRF-TOKEN'] = token.content; window.axios.defaults.headers.common['X-Requested-With'] = 'XMLHttpRequest'; + axios.interceptors.request.use(function (config) { + const url = new URL(config.url); + + if (url.origin !== window.location.origin) { + delete config.headers['X-CSRF-TOKEN']; + } + return config; + }); + document.addEventListener("turbo:before-fetch-request", (event) => { - event.detail.fetchOptions.headers["X-CSRF-TOKEN"] = token.content; + const url = new URL(event.detail.url); + + if (url.origin !== window.location.origin) { + event.detail.fetchOptions.headers["X-CSRF-TOKEN"] = token.content; + } }); }