Search code examples
ember.jsember-simple-auth

Ember Simple Auth - Authorizer not being setup when the session is restored


The code below currently works but If I remove the line with _setup then the outgoing requests don't have the Authorization header.

It doesn't feel like I should be using the _setup function as it isn't in the documentation.

What am I doing wrong?

I'm using the latest version of Ember and Ember-Simple-Auth with the Oauth Password Grant.

Ember.getOwner(this).lookup('authenticator:custom').restore(token).then(() => {
    Ember.getOwner(this).lookup('session:main')._setup('authenticator:custom', token, true);
});

Solution

  • Restore is a convenience function that runs on app startup and store changes. As far as I know, it's not intended to be called manually, but should be firing automatically on app boot and restoring from session data. Whatever you are trying to do by calling restore manually, you could possibly handle inside the authenticate hook instead, passing the token as an argument.

    A canonical call to a custom authenticator should look something like

      session: Ember.inject.service('session'),
      someFunction() {
        let token = this.get('tokenSavedSomewhere')
        this.get('session').authenticate('authenticator:custom', token).catch((reason) => {
          console.log('Reject reason', reason)
        });
      },