mirror of
https://github.com/TryGhost/Ghost.git
synced 2024-12-15 03:12:54 +03:00
33 lines
856 B
JavaScript
33 lines
856 B
JavaScript
import Ember from 'ember';
|
|
import AjaxService from 'ember-ajax/services/ajax';
|
|
|
|
const {inject, computed} = Ember;
|
|
|
|
export default AjaxService.extend({
|
|
session: inject.service(),
|
|
|
|
headers: computed('session.isAuthenticated', function () {
|
|
let session = this.get('session');
|
|
|
|
if (session.get('isAuthenticated')) {
|
|
let headers = {};
|
|
|
|
session.authorize('authorizer:oauth2', (headerName, headerValue) => {
|
|
headers[headerName] = headerValue;
|
|
});
|
|
|
|
return headers;
|
|
} else {
|
|
return [];
|
|
}
|
|
}),
|
|
|
|
normalizeErrorResponse(status, headers, payload) {
|
|
if (payload && typeof payload === 'object') {
|
|
return payload.error || payload.errors || payload.message || false;
|
|
} else {
|
|
return false;
|
|
}
|
|
}
|
|
});
|