Error: null is not an object angularjs + ionic


#1

good friends, I am having the following problem. I have a pretty basic login code, consult my web service parameter sent the login and password if the login is correct return a status parameter {1}, otherwise 0.

At first glance everything works fine, I keep user data with a service, as follows:

.factory('sessionService',['$http',function($http){
  return {
set:function(key,value){
  return localStorage.setItem(key,JSON.stringify(value));
},
get:function(key){
  return JSON.parse(localStorage.getItem(key));
},
destroy:function(key){
  return localStorage.removeItem(key);
},
 };
 }])

When I need to make a logout, I clean any value variables localStorage and again redirected the user to the login page and this is where my error is generated. I get the following error when I try to press the login button. When the application first opens there is no problem, load, send corresponding alerts as “not enter username” or things like that, but at the close session and redirect this page is where the error occurs.

My error :

Error: null is not an object (evaluating 'args[0]')

My function login :

$scope.login = function(){
  $scope.show();
  if(!navigator.onLine){
    $scope.hide();
    $ionicPopup.show({
       title: 'Notificación',
       subTitle: '',
       content: 'No tienes conexión a internet.',
       buttons: [
         {
           text: 'Aceptar',
           type: 'button-positive',
         },
       ]
    })
  }else{
     $http({method: 'GET', url: URL_BASE+'authenticate/'+$scope.data.username+"/"+$scope.data.password})
      .success(function(data){
        if(data.status == 1){
          sessionService.set("user",data.nombre);
          sessionService.set("apellido_paterno", data.apellido_paterno);
          sessionService.set("password",data.password);
          sessionService.set("hash",data.hash);
          sessionService.set("user_id",data.id);
          sessionService.set("email", data.email);
          sessionService.set("mis_views", data.mis_views);
          sessionService.set("photo", data.photo);
          $rootScope.username = sessionService.get("user");
          $rootScope.apellido_paterno = sessionService.get("apellido_paterno");
          $rootScope.photo = sessionService.get("photo");
          $rootScope.mis_views = sessionService.get("mis_views");
          $state.go('eventmenu.home');
        }else{
          var alertPopup = $ionicPopup.alert({
            title: 'Error de Conexión',
            template: 'Tu nombre de usuario o contraseña son incorrectos'
          });
        }
      })
      .error(function(){
        //console.log("Error en la conexion al Servidor")
      })
      .finally(function(){
        $scope.hide();
      });
    }
}

My function logout :

$scope.cerrarSesion = function(){
   localStorage.clear();
   sessionStatus.auth();
} 

My function sessionStatus :

.factory('sessionStatus',['$http','sessionService','$location',function($http,sessionService,$location){
  return {
auth:function(){
  var usuario = sessionService.get("user");
  console.log("USUARIO : "+usuario);
  if((usuario == "") || (usuario == null) || typeof usuario == null){
    $location.path('menu_registro/login');
  }else{
    return true;
  }
},
 };
}])