import Ember from 'ember';

const { service } = Ember.inject;

/**
  This mixin is for routes that require the session to be authenticated to be
  accessible. Including this mixin in a route automatically adds a hook that
  enforces the session to be authenticated and redirects to the
  [`Configuration.authenticationRoute`](#SimpleAuth-Configuration-authenticationRoute)
  if it is not.

  ```js
  // app/routes/protected.js
  import AuthenticatedRouteMixin from 'ember-simple-auth/mixins/authenticated-route-mixin';

  export default Ember.Route.extend(AuthenticatedRouteMixin);
  ```

  `AuthenticatedRouteMixin` performs the redirect in the `beforeModel` method
  so that in all methods executed after that the session is guaranteed to be
  authenticated. __If `beforeModel` is overridden, ensure that the custom
  implementation calls `this._super(transition)`__ so that the session
  enforcement code is actually executed.

  @class AuthenticatedRouteMixin
  @namespace Mixins
  @module ember-simple-auth/mixins/authenticated-route-mixin
  @extends Ember.Mixin
  @static
  @public
*/
export default Ember.Mixin.create({
  session: service('session'),

  ajaxOptions() {
    let hash = this._super(...arguments);
    let { beforeSend } = hash;
    hash.beforeSend = (xhr) => {
      this.get('session').authorize(this.get('authorizer'), (headerName, headerValue) => {
        xhr.setRequestHeader(headerName, headerValue);
      });
      if (beforeSend) {
        beforeSend(xhr);
      }
    };
    return hash;
  },

  handleResponse(status) {
    if (status === 401) {
      this.get('session').invalidate();
      return true;
    } else {
      return this._super(...arguments);
    }
  }
});

@@ -84,309 +84,223 @@
 for 
-rou
+adap
 te
+r
 s 
-that require the session to be authenticated to be%0A  accessible. Including this mixin in a route automatically adds a hook that%0A  enforces the sessi
+and will make authorizing requests as easy as%0A  with the $.ajaxPrefilter before while being much cleaner. All that is to%0A  be d
 on
+e
  to 
-be 
 auth
-enticated and redirects to the%0A  %5B%60Configuration.authenticationRoute%60%5D(#SimpleAuth-Configuration-authenticationRoute)%0A  if it
+orize all Ember Data requests with an authorizer of choice%0A 
  is no
-t.
+w:
 %0A%0A  
@@ -318,24 +318,28 @@
 app/
-rou
+adap
 te
+r
 s/
-protected
+application
 .js%0A
@@ -347,34 +347,58 @@
  import 
-AuthenticatedRou
+DS from 'ember-data';%0A  import DataAdap
 te
+r
 Mixin fr
@@ -426,35 +426,28 @@
 /mixins/
-authenticated-route
+data-adapter
 -mixin';
@@ -469,27 +469,33 @@
 ult 
-Ember.Rou
+DS.JSONAPIAdap
 te
+r
 .extend(
 Auth
@@ -494,410 +494,102 @@
 end(
-AuthenticatedRou
+DataAdap
 te
+r
 Mixin
-);%0A  %60%60%60%0A%0A  %60AuthenticatedRouteMixin%60 performs the redirect in the %60beforeModel%60 method%0A  so that in all methods executed after that the session is guaranteed to be%0A  authenticated. __If %60beforeModel%60 is overridden, ensure that the custom%0A  implementation calls %60this._super(transition)%60__ so that the session%0A  enforcement code is actually executed.%0A%0A  @class AuthenticatedRou
+, %7B%0A    authorizer: 'authorizer:application'%0A  %7D);%0A  %60%60%60%0A%0A  @class DataAdap
 te
+r
 Mixi
@@ -649,27 +649,20 @@
 ins/
-authenticated-route
+data-adapter
 -mix
@@ -710,16 +710,17 @@
 blic%0A*/%0A
+%0A
 export d

Update DataAdapterMixin documentation