Skip to content

Handle x-csrf-token changes via response headers #332

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions src/resources/views/graphiql.php
Original file line number Diff line number Diff line change
Expand Up @@ -79,18 +79,22 @@ function updateURL() {
history.replaceState(null, null, newSearch);
}

var xcrsfToken = null;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Typo: crsf when it should be csrf

Whoever came up with this… 😄


// Defines a GraphQL fetcher using the fetch API.
function graphQLFetcher(graphQLParams) {
return fetch('<?php echo $graphqlPath; ?>', {
method: 'post',
headers: {
'Accept': 'application/json',
'Content-Type': 'application/json',
'X-CSRF-TOKEN': '<?php echo csrf_token(); ?>'
'X-CSRF-TOKEN': xcrsfToken || '<?php echo csrf_token(); ?>'
},
body: JSON.stringify(graphQLParams),
credentials: 'include',
}).then(function (response) {
xcrsfToken = response.headers.get('x-csrf-token');

return response.text();
}).then(function (responseBody) {
try {
Expand All @@ -116,4 +120,4 @@ function graphQLFetcher(graphQLParams) {
);
</script>
</body>
</html>
</html>