Last active
August 24, 2018 22:48
-
-
Save Subtletree/4e651e7d55002054bf2be4bca1530b92 to your computer and use it in GitHub Desktop.
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
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