I am facing an issue where I need to asynchronously insert the headers into the adapter. The token function is responsible for checking if the token has expired, refreshing it via Ajax if needed, and then returning the new token. However, it appears that the adapter is unable to handle the returned promises. Is there anyone who can provide assistance with this problem?
import DS from 'ember-data';
import config from '../config/environment';
export default DS.JSONAPIAdapter.extend({
// Custom application overrides
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()
});