The issue you're facing might be due to the way you're setting the X-XSRF-TOKEN in your axios instance.
In your axios setup, you have withXSRFToken: true, but axios does not have a withXSRFToken option. Instead, axios has an xsrfCookieName option that defines the name of the cookie to use as a value for X-XSRF-TOKEN.
You should set xsrfCookieName to 'XSRF-TOKEN' and xsrfHeaderName to 'X-XSRF-TOKEN' in your axios instance. Here's how you can do it:
const axios = Axios.create({
headers: {
'X-Requested-With': 'XMLHttpRequest',
},
withCredentials: true,
xsrfCookieName: 'XSRF-TOKEN',
xsrfHeaderName: 'X-XSRF-TOKEN',
});
This tells axios to read the CSRF token from the XSRF-TOKEN cookie and set it as the X-XSRF-TOKEN header in the request.
Also, make sure that the XSRF-TOKEN cookie is being set correctly in the /csrf-cookie endpoint response, and that it's being sent with the request. You can check this in your browser's developer tools.
If you're still facing issues, you might want to check your Laravel CSRF middleware and make sure it's configured correctly.