discourse/app/assets/javascripts/discourse/initializers/csrf-token.js.es6
2015-08-13 11:14:16 -04:00

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'));
}
});
}
};