SyliusCrafts / BootstrapTheme

Sylius Bootstrap theme with build process based on Webpack Encore
94 stars 56 forks source link

Error: "Invalid csrf token" on sylius_shop_ajax_cart_item_remove #78

Closed czarnyv closed 3 years ago

czarnyv commented 4 years ago

Ajax request for delete product from cart throws "Invalid csrf token" error, request content is empty, probably it is related with missing content type header. In BootstrapTheme/assets/js/sylius-remove-from-cart.js is:

 axios.delete(url, { data: { _csrf_token: csrfToken } })
      .then(() => { window.location.replace(redirectUrl); });

should be (it works for me):

        axios({
                method: 'DELETE',
                url: url,
                headers: {
                    'Content-Type': 'application/json'
                },
                data: {
                    _csrf_token: csrfToken
                }
            })
                .then(() => {
                    window.location.replace(redirectUrl);
                });
nediam commented 4 years ago

its an axios bug https://github.com/axios/axios/issues/3220

jasonsaayman commented 4 years ago

Hi,

Axios version 0.21.0 has been released 🎉 please use that and let us know if that solves your issue.

Thanks

Tomsgu commented 4 years ago

Thanks for the information. Upgrade Axios to version 0.21.0 fixed the issue for me.