I have a service in place that checks user authentication to determine whether to redirect them to the login page or the logged-in area.
services.js:
var servicesModule = angular.module('servicesModule', []);
servicesModule.service('loginService', ['$state', function($state){
console.log('Inside');
var ref = new Firebase("https://feedback-system.firebaseio.com/");
var authData = ref.getAuth();
console.log('Inside');
if (authData) {
$state.go('tabs.courses');
console.log("User " + authData.uid + " is logged in with " + authData.provider);
} else {
$state.go('login');
}
}]);
Controller:
var ionicApp = angular.module('feedback-system', ['ionic', 'firebase', 'servicesModule', 'coursesModule', 'feedbackModule', 'loginModule', 'tabsModule']);
ionicApp.run(function($ionicPlatform, $state) {
$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) {
StatusBar.styleDefault();
}
});
});
ionicApp.config(function($stateProvider, $urlRouterProvider) {
$stateProvider
.state('login', {
url: '/login',
templateUrl: 'views/login.html',
controller: 'loginCtrl'
})
.state('tabs', {
url: '/tabs',
abstract: true,
templateUrl: 'views/main.html',
controller: 'tabsCtrl'
})
.state('tabs.courses', {
url: '/courses',
views:{
'coursesView':{
templateUrl: 'views/courses.html',
controller: 'coursesCtrl'
}
}
})
.state('tabs.feedback', {
url: '/feedback',
views:{
'feedbackView':{
templateUrl: 'views/feedback.html',
controller: 'feedbackCtrl'
}
}
})
.state('tabs.notifications', {
url: '/notifications',
views:{
'notificationsView':{
templateUrl: 'views/notification.html',
controller: 'notificationCtrl'
}
}
});
$urlRouterProvider.otherwise("/courses");
});
index.html:
<!DOCTYPE html>
<html ng-app="feedback-system">
<head>
<meta charset="utf-8">
<meta name="viewport" content="initial-scale=1, maximum-scale=1, user-scalable=no, width=device-width">
<title></title>
<link href="lib/ionic/css/ionic.css" rel="stylesheet">
<link href="css/style.css" rel="stylesheet">
<!-- IF using Sass (run gulp sass first), then uncomment below and remove the CSS includes above
<link href="css/ionic.app.css" rel="stylesheet">
-->
<!-- ionic/angularjs js -->
<script src="lib/ionic/js/ionic.bundle.js"></script>
<!-- cordova script (this will be a 404 during development) -->
<script src="lib/ngcordova/dist/ng-cordova.js"></script>
<script src="cordova.js"></script>
<!-- Firebase -->
<script src="https://cdn.firebase.com/js/client/2.2.7/firebase.js"></script>
<script src="lib/angularfire.min.js"></script>
<!-- Services -->
<script src="js/services/services.js"></script>
<!-- Controllers -->
<script src="js/controllers/loginCtrl.js"></script>
<script src="js/controllers/coursesCtrl.js"></script>
<script src="js/controllers/feedbackCtrl.js"></script>
<script src="js/controllers/tabsCtrl.js"></script>
<!-- Application -->
<script src="js/app.js"></script>
</head>
<body>
<ion-nav-view></ion-nav-view>
</body>
</html>
The current issue I am facing is that although I have injected the service into the main module and index.html, there are no errors showing up, but the service itself is not being executed. There seems to be no logging activity on the console either.
Update:
On further investigation, it appears that this service was functioning correctly without any need for a return statement previously. However, for some unknown reason, it has ceased to work today.