Problem Login just once with Ionic + Parse


#1

Hello everyone,
I’m developing an app that uses Parse to process login.
I can make the whole process of registration and login fine, but when I close the application reorders login.
I wonder if you know any way to skip the login when the user has already registered once.
The code:

angular.module('starter', ['ionic', 'starter.controllers', 'ngCordova', 'ngIOS9UIWebViewPatch'])




 // Barroso de funcion de abajo $urlRouterProvider


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

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

  })


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

  .state('app.browse', {
    url: "/browse",
    views: {
      'menuContent': {
        templateUrl: "templates/browse.html"
      }
    }
  })
    .state('app.playlists', {
      url: "/playlists",
      views: {
        'menuContent': {
          templateUrl: "templates/playlists.html",
          controller: 'PlaylistsCtrl'
        }
      }
    })
   

    .state('app.posts', {
    url: "/posts/cat/:catslug",
    views: {
      'menuContent': {
        templateUrl: "templates/posts.html",
        controller: 'PostsCtrl' 
      }
    }
  })

  


    .state('app.post', {
    url: "/posts/:postId",
    views: {
      'menuContent': {
        templateUrl: "templates/post.html",
        controller: 'PostCtrl',
      }
    }
  })

   

    .state('app.page', {
    url: "/page/:pageId",
    views: {
    'menuContent': {
        templateUrl: "templates/page.html",
        controller: 'PageCtrl'
      }
    }
    
  })



  .state('app.single', {
    url: "/playlists/:playlistId",
    views: {
      'menuContent': {
        templateUrl: "templates/playlist.html",
        controller: 'PlaylistCtrl'
      }
    }
  })

 // RELATIVO A PARSE
   .state('login', {
    url: '/',
    templateUrl: 'templates/login.html',
    controller: 'LoginCtrl'
  })
  .state('signup', {
    url: '/signup',
    templateUrl: 'templates/signup.html',
    controller: 'LoginCtrl'
  })
  .state('signin', {
    url: '/signin',
    templateUrl: 'templates/signin.html',
    controller: 'LoginCtrl'
  });
 
  $urlRouterProvider.otherwise('app/playlists');
 
})


.run(function($ionicPlatform, $state, $ionicPopup, $rootScope) {

          


  $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();
    };




    if(window.Connection) {
                if(navigator.connection.type == Connection.NONE) {
                    $ionicPopup.confirm({
                        title: "Internet Desconectado",
                        content: "No tiene acceso a internet en su dispositivo."
                    })
                    .then(function(result) {
                        if(!result) {
                            ionic.Platform.exitApp();
                        }
                    });
                }
            }
        


// SET NGCORDOVA
 $cordovaPlugin(function($cordovaSplashscreen) {
  setTimeout(function() {
    $cordovaSplashscreen.hide()
  }, 3000)
})


    // RELATIVO A PARSE
    Parse.initialize("APP", "JS");

    var currentUser = Parse.User.current();
  if (currentUser) {
    $state.go('login');
}else {
  $state.go('app.playlists');
}

  }); 
})

#2

look in this starter application https://github.com/aaronksaunders/parse-starter-ionic