Created
December 11, 2025 18:33
-
-
Save ChrisHagan/7fd7f42c95865ccb485ed1e6a755d45d to your computer and use it in GitHub Desktop.
Extracting the CSRF cookie for reuse in an AJAX patterned call context
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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