mirror of
https://github.com/graphql-python/graphene-django.git
synced 2024-11-22 01:27:01 +03:00
Delay assignment of csrftoken (#1289)
This commit is contained in:
parent
541caa117e
commit
05d3df92e7
|
@ -10,14 +10,6 @@
|
||||||
history,
|
history,
|
||||||
location,
|
location,
|
||||||
) {
|
) {
|
||||||
// Parse the cookie value for a CSRF token
|
|
||||||
var csrftoken;
|
|
||||||
var cookies = ("; " + document.cookie).split("; csrftoken=");
|
|
||||||
if (cookies.length == 2) {
|
|
||||||
csrftoken = cookies.pop().split(";").shift();
|
|
||||||
} else {
|
|
||||||
csrftoken = document.querySelector("[name=csrfmiddlewaretoken]").value;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Collect the URL parameters
|
// Collect the URL parameters
|
||||||
var parameters = {};
|
var parameters = {};
|
||||||
|
@ -68,9 +60,19 @@
|
||||||
var headers = opts.headers || {};
|
var headers = opts.headers || {};
|
||||||
headers['Accept'] = headers['Accept'] || 'application/json';
|
headers['Accept'] = headers['Accept'] || 'application/json';
|
||||||
headers['Content-Type'] = headers['Content-Type'] || 'application/json';
|
headers['Content-Type'] = headers['Content-Type'] || 'application/json';
|
||||||
|
|
||||||
|
// Parse the cookie value for a CSRF token
|
||||||
|
var csrftoken;
|
||||||
|
var cookies = ("; " + document.cookie).split("; csrftoken=");
|
||||||
|
if (cookies.length == 2) {
|
||||||
|
csrftoken = cookies.pop().split(";").shift();
|
||||||
|
} else {
|
||||||
|
csrftoken = document.querySelector("[name=csrfmiddlewaretoken]").value;
|
||||||
|
}
|
||||||
if (csrftoken) {
|
if (csrftoken) {
|
||||||
headers['X-CSRFToken'] = csrftoken
|
headers['X-CSRFToken'] = csrftoken
|
||||||
}
|
}
|
||||||
|
|
||||||
return fetch(fetchURL, {
|
return fetch(fetchURL, {
|
||||||
method: "post",
|
method: "post",
|
||||||
headers: headers,
|
headers: headers,
|
||||||
|
|
Loading…
Reference in New Issue
Block a user