Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
For blog post
const url = ''
fetch(url, { method: "GET", credentials: 'include' }).
then((response) => response.text()).
then((body) => {
const re = new RegExp('<meta name="csrf-token" content="(.*)" />')
const csrfToken = re.exec(body)[1]
return csrfToken
then((csrfToken) => {
const headers = new Headers({'X-CSRF-Token': csrfToken})
fetch(url, {
method: 'POST',
headers: headers,
credentials: 'include'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment