Skip to content

Instantly share code, notes, and snippets.

@nnance
Last active January 2, 2016 17:19
Show Gist options
  • Save nnance/8335518 to your computer and use it in GitHub Desktop.
Save nnance/8335518 to your computer and use it in GitHub Desktop.
Backbone authentication using auth headers
define(function (require) {
"use strict";
var Backbone = require('backbone');
return Backbone.Model.extend({
initialize: function() {
this.backboneSync = Backbone.sync;
},
initAuthentication: function(user) {
var backboneSync = this.backboneSync;
Backbone.sync = function (method, model, options) {
options.headers = {
'Auth-User': user.id,
'Auth-Token': user.get('token')
};
backboneSync(method, model, options);
};
},
removeAuthentication: function() {
Backbone.sync = this.backboneSync;
}
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment