Skip to content

Instantly share code, notes, and snippets.

@Subtletree
Last active August 24, 2018 22:48
Show Gist options
  • Save Subtletree/4e651e7d55002054bf2be4bca1530b92 to your computer and use it in GitHub Desktop.
Save Subtletree/4e651e7d55002054bf2be4bca1530b92 to your computer and use it in GitHub Desktop.
import Service from '@ember/service';
import fetch from 'fetch';
export default Service.extend({
session: service(),
request({ url, method, cache, headers = {}, contentType, body } = {}) {
headers = this._processHeaders(headers);
return fetch(url, {
method,
cache,
headers,
contentType,
body
});
},
headers: computed('session.data.authenticated.access_token', function() {
const token = this.session.data.authenticated.access_token;
return token ? { 'Authorization': `Bearer ${token}` } : {};
}),
_processHeaders(headers) {
return Object.assign({}, this.headers, headers);
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment