Last active
January 2, 2016 17:19
-
-
Save nnance/8335518 to your computer and use it in GitHub Desktop.
Backbone authentication using auth headers
This file contains 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
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