Saleor Core: the high performance, composable, headless commerce API.
Python cartcheckoutcommercecomposablee-commerceecommercegraphqlheadlessheadless-commercemultichannelomsorder-managementpaymentspimpythonshopshopping-cartstore
Require CSRF token for request from Relay
Marcin Gębala95588e80b2b0
diff --git a/saleor/static/js/category.js b/saleor/static/js/category.jsindex 6a1d4fefb6..ffab0a8fbb 100644--- a/saleor/static/js/category.js+++ b/saleor/static/js/category.js@@ -8,11 +8,6 @@ import ProductFilters from './components/categoryPage/ProductFilters';const categoryPage = document.getElementById('category-page');const categoryData = JSON.parse(categoryPage.getAttribute('data-category'));-Relay.injectNetworkLayer(- new Relay.DefaultNetworkLayer('/graphql/', {- credentials: 'same-origin',- })-);class App extends React.Component {diff --git a/saleor/static/js/storefront.js b/saleor/static/js/storefront.jsindex ad06d19fcf..5c928ff827 100644--- a/saleor/static/js/storefront.js+++ b/saleor/static/js/storefront.js@@ -2,6 +2,7 @@ import '../scss/storefront/storefront.scss'import 'jquery.cookie'import React from 'react'import ReactDOM from 'react-dom'+import Relay from 'react-relay';import VariantPicker from './components/variantPicker/VariantPicker'@@ -19,6 +20,15 @@ $.ajaxSetup({}})+Relay.injectNetworkLayer(+ new Relay.DefaultNetworkLayer('/graphql/', {+ credentials: 'same-origin',+ headers: {+ 'X-CSRFToken': csrftoken,+ },+ })+)+var getAjaxError = (response) => {var ajaxError = $.parseJSON(response.responseText).error.quantityreturn ajaxErrordiff --git a/saleor/urls.py b/saleor/urls.pyindex de3b581cce..ab636f98d9 100644--- a/saleor/urls.py+++ b/saleor/urls.py@@ -4,7 +4,6 @@ from django.conf.urls.static import staticfrom django.contrib import adminfrom django.contrib.sitemaps.views import sitemapfrom django.contrib.staticfiles.views import serve-from django.views.decorators.csrf import csrf_exemptfrom graphene_django.views import GraphQLViewfrom .cart.urls import urlpatterns as cart_urls@@ -28,7 +27,7 @@ urlpatterns = [url(r'^cart/', include(cart_urls, namespace='cart')),url(r'^checkout/', include(checkout_urls, namespace='checkout')),url(r'^dashboard/', include(dashboard_urls, namespace='dashboard')),- url(r'^graphql', csrf_exempt(GraphQLView.as_view(graphiql=True))),+ url(r'^graphql', GraphQLView.as_view(graphiql=True)),url(r'^order/', include(order_urls, namespace='order')),url(r'^products/', include(product_urls, namespace='product')),url(r'^profile/', include(userprofile_urls, namespace='profile')),diff --git a/templates/category/index.html b/templates/category/index.htmlindex 8979262667..f0e6400294 100644--- a/templates/category/index.html+++ b/templates/category/index.html@@ -25,5 +25,6 @@{% endblock breadcrumb %}{% block content %}+ {% csrf_token %}<div id="category-page" data-category='{"id":{{category.id}}}'></div>{% endblock content %}