Hi, I am new to ionic structure. I use the session manager in ion mode. But I want to skip the login page if the user is already logged in.
app.js
angular.module('grocery', ['ionic', 'grocery.controller', 'ngCordova', 'ngCordovaOauth']) .run(function($ionicPlatform, $cordovaSQLite, $cordovaToast, $rootScope, mainItemsList, $state) { $ionicPlatform.ready(function() { if (window.cordova && window.cordova.plugins.Keyboard) { cordova.plugins.Keyboard.hideKeyboardAccessoryBar(true); stops the viewport // from snapping when text inputs are focused. Ionic handles this internally for // a much nicer keyboard experience. cordova.plugins.Keyboard.disableScroll(true); } if (window.StatusBar) { StatusBar.styleDefault(); } }); }); $rootScope.$on('$locationChangeStart', function(event, newUrl, oldUrl) { if (mainItemsList.isLoggedIn() != true) { $state.go('app.login'); } }) .config(function($stateProvider, $urlRouterProvider) { $stateProvider .state('app', { url: "/app", abstract: true, templateUrl: "templates/navigationDrawer.html", controller: 'AppCtrl' }) .state('app.masterList', { url: "/masterList", views: { 'menuContent': { templateUrl: "templates/masterList.html", controller: 'indexCtrl' } } }) .state('app.login', { url: "/login", views: { 'menuContent': { templateUrl: "templates/login.html", controller: 'loginCtrl' } } }) .state('app.register', { url: "/register", views: { 'menuContent': { templateUrl: "templates/register.html", controller: 'registerCtrl' } } }) $urlRouterProvider.otherwise("/app/masterList"); }); angular.module('grocery.services', []) .factory('mainItemsList', function($cordovaSQLite, $cordovaToast, $cordovaPreferences) { return { isLoggedIn: function(sessionEmail) { $cordovaPreferences.store('email', sessionEmail).success(function(value) { //$cordovaToast.showShortTop('stored'); }) .error(function(error) { $cordovaToast.showShortTop("Error " + error); }) return true; } } })
I tried existing stackoverflow answers. But does not work. please help me where am i wrong.
source share