Skip to content

Instantly share code, notes, and snippets.

@ChrisHagan
Created December 11, 2025 18:33
Show Gist options
  • Select an option

  • Save ChrisHagan/7fd7f42c95865ccb485ed1e6a755d45d to your computer and use it in GitHub Desktop.

Select an option

Save ChrisHagan/7fd7f42c95865ccb485ed1e6a755d45d to your computer and use it in GitHub Desktop.
Extracting the CSRF cookie for reuse in an AJAX patterned call context
function(item, payload) {
const possibleReminder = payload.get('upgrade').map(upgrade => {
const task = {
title: upgrade.args.title,
text: upgrade.args.description,
importance: 10,
reminders: []
};
var conf = getConfig('pathify_configurations').get();
const body = JSON.stringify(task).getBytes("UTF-8");
var csrf;
payload.getState().get('req').map(req =>
toKVMap(req.headers()).get('Cookie').map(cookies => {
csrf = cookies.match(new RegExp("csrftoken=(.+?);"))[1];
}))
return [
new code_data_generic_ApiRequest(
conf['api-url'] + '/v1/users/me/tasks/',
'POST',
Some(body),
toKVList([
['Content-Type', 'application/json'],
['X-CSRFToken', csrf]
])
)
];
}).getOrElse(_.constant([]));
return possibleReminder;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment