I need to insert the headers into the adapter asynchronously because the token function should check if the token is not expired and refresh it (per Ajax) if it is expired and then return the new token. But it seems the adapter can't handle the returned promises. Can anybody help me out with that issue?
import DS from 'ember-data';
import config from '../config/environment';
export default DS.JSONAPIAdapter.extend({
// Application specific overrides go here
host: config.APP.api_endpoint,
headers: Ember.computed(function() {
return this.auth.getToken().then(
(accessToken) => {
if (accessToken) {
const auth = `Bearer ${accessToken}`;
return {
Authorization: auth
};
} else {
return {
};
}
});
}).volatile()
});
Aucun commentaire:
Enregistrer un commentaire