title: Need to inject model into services, Ember JS
body: <p>Need Help,</p>
  
  <p>I'm really new to Ember and trying to get a Auth service working for login/out in CLI... However I can't seem to be able to call any of the handy ORM helpers without getting a undefined error... </p>
  
  <p>I did get it working with straight old jquery ajax, but I really want to get this working with the rest adapter. </p>
  
  <p>SERVICES/AUTHENTICATION.JS</p>
  
  <pre><code>import Ember from 'ember';
  import DS from 'ember-data';
  import App from '../app.js';
  import User from '../models/user.js';
  import ApiKey from '../models/api-key.js';
  
  export default Ember.Object.extend({
  
  //load the current user if the cookies exist and is valid
  init: function() {
      this._super();
      var accessToken = Ember.$.cookie('access_token');
      var authUserId = Ember.$.cookie('auth_user');
      if (!Ember.isEmpty(accessToken) &amp;&amp; !Ember.isEmpty(authUserId)) {
          this.authenticate(accessToken, authUserId);
      }
   },
  
  //determine if the user is currently authenticated
  isAuthenticated: function() {
      return !Ember.isEmpty(this.get('apiKey.accessToken')) &amp;&amp;       !Ember.isEmpty(this.get('apiKey.user'));
  },
  
  // Auth the user. Once they are auth, set access token to be submitted    with all
  // future AJAX requests 
  authenticate: function(accessToken, userId) {
      Ember.$.ajaxSetup({
          headers: { 'Authorization': 'Bearer ' + accessToken }
      });
      user = User.find(userId)
      this.set('apiKey', ApiKey.create({
       accessToken: accessToken,
       user: user
      }));
     },
  
     //log out the user 
     reset: function({
  App.__container__.lookup('route:application').transitionTo('session.new');
      Ember.run.sync();
      Ember.run.next('apiKey', null);
      Ember.$.ajaxSetup({
          headers: { 'Authorization' : 'Bearer none' }
      });
  },
  
  // Ensure that when the browser the cookies are refreshed 
  apiKeyObserver: function() {
      if (Ember.isEmpty(this.get('apiKey'))) {
          Ember.$.removeCookie('access_token');
          Ember.$.removeCookie('auth_user');
      } else {
          Ember.$.cookie('access_token', this.get('apiKey.accessToken'));
          Ember.$.cookie('auth_user', this.get('apiKey.user.id'));
      }
  }
  });
  
  // // Reset the authentication if any ember data request returns a 401     unauthorized error
  DS.rejectionHandler = function(reason) {
    if (reason.status === 401) {
      App.AuthManager.reset();
    }
  throw reason;
  };
  </code></pre>