Quantcast
Channel: Ember.JS - Latest topics
Viewing all articles
Browse latest Browse all 4870

Async field in Ember adapter

$
0
0

I have the following situation:

export default class ApplicationAdapter extends JSONAPIAdapter {
  @service auth;
  @tracked bearer;

  namespace = 'api/v1';
  host = ENV.host;
  headers = {
    'Authorization': this.authorize()
  }

  async authorize() {
    const accessToken = await this.auth.checkLogin();
    return `Bearer ${accessToken}`;
  }
}

as I want to to get the accessToken from the async checkLogin function in my not-async headers it does not work. I get a authorization: [object Promise] back and not the accesstoken.

How do I solve this as I cannot make the headers field async?

4 posts - 2 participants

Read full topic


Viewing all articles
Browse latest Browse all 4870

Trending Articles