CSRF token in Vue.js Storefront in Shopware 6

Viewed 506

I am using a custom instance of Vue.js in the storefront. But I’m having some issues with adding items to the cart. Or any API calls for that instance. I need a CSRF token for API call, but I have no idea how to retrieve this token from inside my Vue.js storefront, because I’m not using twig. Is there a way to get this token inside a Vue storefront?

In the twig files you can do something like this:

{% block page_product_detail_buy_form_inner_csrf %}
    {{ sw_csrf('frontend.checkout.line-item.add') }}
{% endblock %}

But inside vue you can't use code like this. Is there a way to achieve this in my Vue storefront?

1 Answers
Related