Skip to content

Instantly share code, notes, and snippets.

@j-mcnally
Created November 4, 2017 19:29
Show Gist options
  • Save j-mcnally/23f47198f6a80e963dab4ad748a73951 to your computer and use it in GitHub Desktop.
Save j-mcnally/23f47198f6a80e963dab4ad748a73951 to your computer and use it in GitHub Desktop.
import _fetch from 'fetch'
import Config from '../config/environment';
import Ember from 'ember'
export default Ember.Service.extend({
session: Ember.inject.service('session'),
fetch(url, options={}) {
return new Promise((resolve, reject) => {
this.get('session').authorize('authorizer:devise', (headerName, headerContent) => {
options = Object.assign({headers: {}}, options)
let authHeaders = {}
authHeaders[headerName] = headerContent
options["headers"] = Object.assign(options["headers"], authHeaders)
resolve(_fetch(`${Config.api.host}${url}`, options));
});
});
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment