Skip to content

Instantly share code, notes, and snippets.

@linuxsable
Created April 17, 2013 20:45
Show Gist options
  • Save linuxsable/5407607 to your computer and use it in GitHub Desktop.
Save linuxsable/5407607 to your computer and use it in GitHub Desktop.
// Setup backbone to handle auth tokens
// in all it's requests by override the sync method.
_setupAuthToken: function() {
var _sync = Backbone.sync;
Backbone.sync = function(method, model, options) {
options = options || {};
options.beforeSend = function(xhr, options) {
var _data = options.data;
var newData = _.extend(JSON.parse(options.data), {
auth_token: IS.currentUser.get('authToken'),
api_key: IS.CONSTANTS.API_KEY
});
options.data = JSON.stringify(newData);
};
_sync.call(this, method, model, options);
};
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment