mirror of
https://github.com/codeninjasllc/discourse.git
synced 2024-11-29 18:46:23 -05:00
17 lines
499 B
JavaScript
17 lines
499 B
JavaScript
// Append our CSRF token to AJAX requests when necessary.
|
|
export default {
|
|
name: "csrf-token",
|
|
initialize: function(container) {
|
|
|
|
var session = container.lookup('session:main');
|
|
|
|
// Add a CSRF token to all AJAX requests
|
|
session.set('csrfToken', $('meta[name=csrf-token]').attr('content'));
|
|
|
|
$.ajaxPrefilter(function(options, originalOptions, xhr) {
|
|
if (!options.crossDomain) {
|
|
xhr.setRequestHeader('X-CSRF-Token', session.get('csrfToken'));
|
|
}
|
|
});
|
|
}
|
|
};
|