How to change states when logging in or logging out with firebase without refreshing?

I am trying to use resolve to check for the authentication state and direct the user to the appropriate view.

I am trying the following (see below), but it does not result in transferring to the appropriate states as it would have done when refreshing the page.

app.js

// Ionic Starter App

// angular.module is a global place for creating, registering and retrieving Angular modules
// 'starter' is the name of this angular module example (also set in a <body> attribute in index.html)
// the 2nd parameter is an array of 'requires'
// 'starter.controllers' is found in controllers.js
angular.module('starter', ['ionic', 'starter.controllers', 'firebase'])

.run(function($ionicPlatform) {
  $ionicPlatform.ready(function() {
    // Hide the accessory bar by default (remove this to show the accessory bar above the keyboard
    // for form inputs)
    if (window.cordova && window.cordova.plugins.Keyboard) {
      cordova.plugins.Keyboard.hideKeyboardAccessoryBar(true);
    }
    if (window.StatusBar) {
      // org.apache.cordova.statusbar required
      StatusBar.styleDefault();
    }
  });
})

.run(["$rootScope", "$state", function($rootScope, $state) {
  $rootScope.$on("$stateChangeError", function(event, toState, toParams, fromState, fromParams, error) {
    // We can catch the error thrown when the $requireAuth promise is rejected
    // and redirect the user back to the home page
    if (error === "AUTH_REQUIRED") {
      console.log('stateChangeError')
      $state.go("app.login");
    }
  });
}])

.config(function($stateProvider, $urlRouterProvider) {

  var authResolve = {
    authReturn: function($state, $q, $timeout, Auth) {
      var defer = $q.defer();
      var ref = Auth.refObj();


      ref.onAuth(authDataCallback)


      function authDataCallback(authData) {
        if (authData) {
          console.log("authDataCallback: User " + authData.uid + " is logged in with " + authData.provider);
          defer.resolve(authData)
        }   else {
          console.log("authDataCallback: User is logged out");
          defer.reject('AUTH_REQUIRED')
        }
      }




      $timeout(function() { // See: http://stackoverflow.com/q/24945731/247243
          defer.reject('login');
      }, 250);

      return defer.promise;
    }
  };


  $stateProvider

  .state('app', {
    url: "/app",
    abstract: true,
    templateUrl: "templates/menu.html",
    controller: 'AppCtrl'
  })

  .state('app.login', {
    url: "/login",
    views: {
      'menuContent': {
        templateUrl: "templates/login.html",
        controller: "LoginCtrl"
      }
    }
  })

  .state('app.profile', {
    url: "/profile",
    views: {
      'menuContent': {
        templateUrl: "templates/profile.html",
        resolve: authResolve
      }
    }
  })

  // if none of the above states are matched, use this as the fallback
  $urlRouterProvider.otherwise('/app/login'); //CHANGE TO HOME
});

controller.js

angular.module('starter.controllers', [])

.controller('AppCtrl', function($scope) {

})

.controller('LoginCtrl', function($scope, $timeout, $state, Auth) {

  var ref = Auth.refObj();
  var authData = ref.getAuth();

if (authData) {
  console.log("User " + authData.uid + " is logged in with " + authData.provider);
  $scope.authData = authData;
} else {
  console.log("User is logged out");
}

  $scope.signOut = function() {
    Auth.signOut();
  }

  $scope.signIn = function() {
    Auth.signIn();
  }

})


.factory('Auth', function($firebase, $firebaseAuth, $state) {

  // Register the callback to be fired every time auth state changes
  var ref = new Firebase("https://lovin.firebaseio.com");

  var signIn = function() {
    ref.authWithPassword({
        email    : 'sa.ibisevic@gmail.com',
        password : 'Maserati2014'
    }, authHandler);

    // logging users in
    function authHandler(error, authData) {
      if (error) {
        console.log("Login Failed!", error);
        $state.go("app.login")
      } else {
        console.log("Authenticated successfully with payload:", authData);
        $state.go("app.profile")
      }
    }

  }

  var signOut = function() {
    ref.unauth();
    $state.go("app.login")
  }

  var authRef = function() {
    return $firebaseAuth(ref);
  }



  return {

    signIn: signIn,
    signOut: signOut,
    refObj: function() {
      return ref;
    },
    authRef: authRef

  }


})

login.html

<ion-view view-title="Login">


  <ion-nav-bar class="bar-stable">

      <ion-nav-buttons side="left">
        <button class="button button-icon button-clear ion-navicon" menu-toggle="left">
        </button>
      </ion-nav-buttons>
    </ion-nav-bar>

  <ion-content>
    <h1>{{authData.uid}}</h1>

    <button class="button" ng-click="signIn()">Sign In</button>
    <button class="button" ng-click="signOut()">Sign Out</button>

  </ion-content>
</ion-view>

Beware that you can listen to the authentication state on the $firebaseSimpleLogin object. So you could do something like that:

 $rootScope.$on('$firebaseSimpleLogin:logout', function(event) {

    $state.go('login');

  });

Hope this helps.