fenichelar/ember-simple-auth-token

Release a version compatible with ESA v3.1.0

gwak opened this issue · 5 comments

gwak commented

Hi,

We're currently migrating our app off of mixins. We have used ember-simple-auth with ember-simple-auth-token successfully in the past.
Now that ember-simple-auth has released the final v3.1.0 version, is there a compatible version of ember-simple-auth-token in the works ?
If not, is it feasible soon ?

Thanks

@gwak while I have not personally tested it yet, I don't see any reason you can't use the latest version of ember-simple-auth-token with ember-simple-auth@3.1.0. Are you running into any issues?

I'm experiencing the same issue, for me its mostly that the "DataAdapterMixin" is deprecated which is causing lots of warnings in the new versions.

https://github.com/simplabs/ember-simple-auth/blob/master/guides/upgrade-to-v3.md#refactor-ember-data-adapters-to-remove-use-of-authorizers

The ember-simple-auth-token mixins use the DataAdapterMixin. But you don't need to use the supplied mixins and probably shouldn't. With Octance, mixins aren't considering a good practice.

I have not had an opportunity to add text to the readme to describe how to use ember-simple-auth-token without the provided mixins. But the ember-simple-auth readme provides the information needed. Basically, do this in you adapter:

import { inject } from '@ember/service';
import { computed } from '@ember/object';
import DS from 'ember-data';

export default DS.RESTAdapter.extend({
  session: inject('session'),

  headers: computed('session.isAuthenticated', 'session.data.authenticated.token', function() {
    if (this.session.isAuthenticated) {
      return {
        Authorization: `Bearer ${this.session.data.authenticated.token}`,
      };
    } else {
      return {};
    }
  }),

  handleResponse(status) {
    if (status === 401 && this.session.isAuthenticated) {
      this.session.invalidate();
    }
    return this._super(...arguments);
  },
});

Thank you, I was able to remove the token mixin use with this.

I have updated the documentation: #299