Skip to content

Commit 05d3df9

Browse files
authored
Delay assignment of csrftoken (#1289)
1 parent 541caa1 commit 05d3df9

File tree

1 file changed

+10
-8
lines changed

1 file changed

+10
-8
lines changed

graphene_django/static/graphene_django/graphiql.js

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,6 @@
1010
history,
1111
location,
1212
) {
13-
// Parse the cookie value for a CSRF token
14-
var csrftoken;
15-
var cookies = ("; " + document.cookie).split("; csrftoken=");
16-
if (cookies.length == 2) {
17-
csrftoken = cookies.pop().split(";").shift();
18-
} else {
19-
csrftoken = document.querySelector("[name=csrfmiddlewaretoken]").value;
20-
}
2113

2214
// Collect the URL parameters
2315
var parameters = {};
@@ -68,9 +60,19 @@
6860
var headers = opts.headers || {};
6961
headers['Accept'] = headers['Accept'] || 'application/json';
7062
headers['Content-Type'] = headers['Content-Type'] || 'application/json';
63+
64+
// Parse the cookie value for a CSRF token
65+
var csrftoken;
66+
var cookies = ("; " + document.cookie).split("; csrftoken=");
67+
if (cookies.length == 2) {
68+
csrftoken = cookies.pop().split(";").shift();
69+
} else {
70+
csrftoken = document.querySelector("[name=csrfmiddlewaretoken]").value;
71+
}
7172
if (csrftoken) {
7273
headers['X-CSRFToken'] = csrftoken
7374
}
75+
7476
return fetch(fetchURL, {
7577
method: "post",
7678
headers: headers,

0 commit comments

Comments
 (0)