title: Getting ng-token-auth to work with devise_token_auth
body: <p>I have a Rails and Ionic project.  The back-end uses the devise_token_auth Gem, and the front end ng-token-auth; these are supposed to work "seamlessly".</p>
  
  <p>I've got everything working as far as registration and sign in, which returns a valid response object.  Hoever, any further requests after I use $state.go('app.somepage') result in 401 Unauthorized responses.</p>
  
  <p>I get the sense that I'm not actually storing the token anywhere.  Can someone please help?</p>
  
  <p>Here are some snippets:</p>
  
  <pre><code>    .controller('LoginCtrl',['$scope', '$auth', '$state', function($scope, $auth, $state) {
      $scope.loginForm = {}
      $scope.handleLoginBtnClick = function() {
        console.log($scope.loginForm);
        $auth.submitLogin($scope.loginForm)
            .then(function(resp) {
              $state.go('app.feed');
            })
            .catch(function(resp) {
              console.log(resp.errors);
            });
      };
  </code></pre>
  
  <p>State definition:</p>
  
  <pre><code>    .state('app', {
    url: "/app",
    abstract: true,
    templateUrl: "templates/menu.html",
    controller: 'AppCtrl',
    resolve: {
      auth: function($auth) {
        return $auth.validateUser();
      }
    }
  
  })
  </code></pre>
  
  <p>Resources:</p>
  
  <pre><code>factory('Post', ['railsResourceFactory', 'apiUrl', function (railsResourceFactory, apiUrl) {
      return railsResourceFactory({
          url: apiUrl + '/posts',
          name: 'post'
      });
  }]).
  </code></pre>
  
  <p>And in PostsCtrl:</p>
  
  <pre><code>  $scope.loadFeed = function() {
      Post.query().then(function (posts) {
        $scope.posts = posts;
      }, function (error) {
        console.log( 'Did not get posts!'); ### THIS FIRES
      }).finally(function() {
        // Stop the ion-refresher from spinning
        $scope.$broadcast('scroll.refreshComplete');
      });
    };
  </code></pre>
  
  <p>Login response object:</p>
  
  <pre><code>{"data":{"id":1,"provider":"email","uid":"1234","phone":null,"name":"Admin","image":null,"username":"admin"}}
  </code></pre>
  
  <p>Top of ApplicationController:</p>
  
  <pre><code>class ApplicationController &lt; ActionController::Base
    include DeviseTokenAuth::Concerns::SetUserByToken
  
    before_filter :add_allow_credentials_headers
    before_filter :cors_preflight_check
    after_filter :cors_set_access_control_headers
    before_action :configure_permitted_parameters, if: :devise_controller?
  
    ..yadayada...
  
    def configure_permitted_parameters
      devise_parameter_sanitizer.for(:sign_up) &lt;&lt; :phone
      devise_parameter_sanitizer.for(:sign_up) &lt;&lt; :username
      devise_parameter_sanitizer.for(:sign_up) &lt;&lt; :session
  
      devise_parameter_sanitizer.for(:sign_in) &lt;&lt; :phone
      devise_parameter_sanitizer.for(:sign_in) &lt;&lt; :username
      devise_parameter_sanitizer.for(:sign_in) &lt;&lt; :session
    end
  </code></pre>
  
  <p>And some default models for User on the rails side.</p>
  
  <p>Rails log:</p>
  
  <pre><code>Started GET "/posts" for 192.168.83.26 at 2015-02-24 23:29:02 -0500
  Processing by PostsController#index as JSON
    Parameters: {"post"=&gt;{}}
  Filter chain halted as :authenticate_user! rendered or redirected
  Completed 401 Unauthorized in 1ms (Views: 0.2ms | ActiveRecord: 0.0ms)
  </code></pre>
  
  <p>If anyone can provide some insight that would be wonderful.  I'm happy to post more snippets as needed.</p>