Skip to content

Instantly share code, notes, and snippets.

@hpjaj
Created November 14, 2018 18:05
Show Gist options
  • Save hpjaj/9b6b923b42017c094f07c6982fd72a0a to your computer and use it in GitHub Desktop.
Save hpjaj/9b6b923b42017c094f07c6982fd72a0a to your computer and use it in GitHub Desktop.
// app/javascript/util/helpers.js
function csrfToken(document) {
return document.querySelector('[name="csrf-token"]').content;
}
export function passCsrfToken(document, axios) {
axios.defaults.headers.common['X-CSRF-TOKEN'] = csrfToken(document);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment