Skip to content

Commit db97953

Browse files
committed
fix response error in axios hook
1 parent aa4cf58 commit db97953

File tree

3 files changed

+8
-5
lines changed

3 files changed

+8
-5
lines changed

src/web/assets/axioshook/dist/index.js

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,12 @@ const l = (t) => {
4040
}
4141
return t;
4242
}), window.axios.interceptors.response.use(
43-
async (t) => (t.config.data.get("action") == "users/login" && await s().then((n) => {
44-
c(n.csrfTokenName, n.csrfTokenValue);
45-
}), t)
43+
async (t) => {
44+
var n;
45+
return ((n = t.config.data) == null ? void 0 : n.get("action")) == "users/login" && await s().then((e) => {
46+
c(e.csrfTokenName, e.csrfTokenValue);
47+
}), t;
48+
}
4649
);
4750
}, d = async () => {
4851
let n = 0;
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
(function(s){typeof define=="function"&&define.amd?define(s):s()})(function(){"use strict";const s="/actions/users/session-info",c=async function(){return await fetch(s,{headers:{Accept:"application/json"}}).then(t=>t.json())};let a=null;const u=t=>{const e=new URL(t).pathname,o=window.location.pathname.split("/");o.pop();const d=o.join("/");return e.replace(d,"").replace(/^\//,"")},r=()=>{const t=document.head.querySelector("meta[csrf]");if(!t)return null;const n=t==null?void 0:t.getAttribute("name"),e=t==null?void 0:t.getAttribute("content");return{csrfTokenName:n??"CRAFT_CSRF_TOKEN",csrfTokenValue:e??""}},i=(t,n)=>{let e=document.head.querySelector("meta[csrf]");e?(e.setAttribute("name",t),e.setAttribute("content",n)):(e=document.createElement("meta"),e.setAttribute("csrf",""),e.setAttribute("name",t),e.setAttribute("content",n),document.head.appendChild(e))},l=async()=>{window.axios.defaults.headers={"Content-Type":"multipart/form-data"},window.axios.interceptors.request.use(async t=>{if(t.method==="post"||t.method==="put"){let n=r();n||(a=await c(),a.isGuest||(i(a.csrfTokenName,a.csrfTokenValue),n=r()));const e=n||a;if(!e)throw new Error("CSRF token not found");const o=u(t.url);t.url="",t.data instanceof FormData?(t.data.append(e.csrfTokenName,e.csrfTokenValue),t.data.append("action",o)):t.data={[e.csrfTokenName]:e.csrfTokenValue,action:o,...t.data}}return t}),window.axios.interceptors.response.use(async t=>(t.config.data.get("action")=="users/login"&&await c().then(n=>{i(n.csrfTokenName,n.csrfTokenValue)}),t))};(async()=>{let n=0;const e=setInterval(async()=>{if(window.axios){clearInterval(e),await l();return}n++,n>=40&&(clearInterval(e),console.warn("Inertia (Craft): Axios not found after 10 seconds. CSRF protection may not be active."))},250)})()});
1+
(function(s){typeof define=="function"&&define.amd?define(s):s()})(function(){"use strict";const s="/actions/users/session-info",c=async function(){return await fetch(s,{headers:{Accept:"application/json"}}).then(t=>t.json())};let a=null;const u=t=>{const e=new URL(t).pathname,o=window.location.pathname.split("/");o.pop();const d=o.join("/");return e.replace(d,"").replace(/^\//,"")},r=()=>{const t=document.head.querySelector("meta[csrf]");if(!t)return null;const n=t==null?void 0:t.getAttribute("name"),e=t==null?void 0:t.getAttribute("content");return{csrfTokenName:n??"CRAFT_CSRF_TOKEN",csrfTokenValue:e??""}},i=(t,n)=>{let e=document.head.querySelector("meta[csrf]");e?(e.setAttribute("name",t),e.setAttribute("content",n)):(e=document.createElement("meta"),e.setAttribute("csrf",""),e.setAttribute("name",t),e.setAttribute("content",n),document.head.appendChild(e))},l=async()=>{window.axios.defaults.headers={"Content-Type":"multipart/form-data"},window.axios.interceptors.request.use(async t=>{if(t.method==="post"||t.method==="put"){let n=r();n||(a=await c(),a.isGuest||(i(a.csrfTokenName,a.csrfTokenValue),n=r()));const e=n||a;if(!e)throw new Error("CSRF token not found");const o=u(t.url);t.url="",t.data instanceof FormData?(t.data.append(e.csrfTokenName,e.csrfTokenValue),t.data.append("action",o)):t.data={[e.csrfTokenName]:e.csrfTokenValue,action:o,...t.data}}return t}),window.axios.interceptors.response.use(async t=>{var n;return((n=t.config.data)==null?void 0:n.get("action"))=="users/login"&&await c().then(e=>{i(e.csrfTokenName,e.csrfTokenValue)}),t})};(async()=>{let n=0;const e=setInterval(async()=>{if(window.axios){clearInterval(e),await l();return}n++,n>=40&&(clearInterval(e),console.warn("Inertia (Craft): Axios not found after 10 seconds. CSRF protection may not be active."))},250)})()});

src/web/assets/axioshook/src/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ const configureAxios = async () => {
125125
// Add a response interceptor
126126
(window.axios as AxiosInstance).interceptors.response.use(
127127
async (response) => {
128-
if (response.config.data.get("action") == "users/login") {
128+
if (response.config.data?.get("action") == "users/login") {
129129
await getSessionInfo().then((sessionInfo) => {
130130
setCsrfOnMeta(sessionInfo.csrfTokenName, sessionInfo.csrfTokenValue);
131131
});

0 commit comments

Comments
 (0)