Skip to content

Instantly share code, notes, and snippets.

@marcoow
Last active December 18, 2015 14:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save marcoow/5796449 to your computer and use it in GitHub Desktop.
Save marcoow/5796449 to your computer and use it in GitHub Desktop.
custom REST adapter for ember-data that sends the authentication token in a header
App.AuthenticatedRESTAdapter = DS.RESTAdapter.extend({
ajax: function(url, type, hash) {
hash = hash || {};
hash.headers = hash.headers || {};
hash.headers['X-AUTHENTICATION-TOKEN'] = this.authToken;
return this._super(url, type, hash);
}
});
@themouette
Copy link

After looking around a bit, it appears that the headers property is designed for this:

App.AuthenticatedRESTAdapter = DS.RESTAdapter.extend({
  headers: Ember.computed('session.authToken',  function () {
    return {
      'X-AUTHENTICATION-TOKEN': this.get('session.authToken')
    };
  });
});

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment