     $state.go 'login'
 
   $rootScope.$on 'auth:already_logged', (msg, data) ->
-    prev = $rootScope.previousState
     $state.go 'home'
 
   $rootScope.$on 'connection_refused', (msg, data) ->


  # State utils
  $rootScope.goBack = ->
    prev = $rootScope.previousState

    if prev
      $state.go prev.name, prev.params
    else
      $state.go 'home'

  $rootScope.goToNextState = ->
    next = $rootScope.nextState

    if next
      $state.go next.name, next.params
    else
      $state.go 'home'


  # Keep track of previous and current states.
  $rootScope.$on '$stateChangeSuccess', (ev, to, toParams, from, fromParams) ->
    $rootScope.previousState =
      state  : from
      params : fromParams

    $rootScope.currentState =
      state  : to
      params : toParams

    $rootScope.nextState = undefined
