I am new to working with AngularJS and I have been experimenting with the generator-angular-fullstack,
My goal is to have the login page load first instead of the main page. After playing around with the code, I found a solution by adding 'authenticate: true' in MainCtrl
angular.module('myapp')
.config(function ($stateProvider) {
$stateProvider
.state('main', {
url: '/',
templateUrl: 'app/main/main.html',
controller: 'MainCtrl',
authenticate: true
});
});
I also commented out the line 'event.preventDefault();' in app.js within the run function
.run(function ($rootScope, $location, Auth) {
// Redirect to login if route requires auth and you're not logged in
$rootScope.$on('$stateChangeStart', function (event, next) {
Auth.isLoggedInAsync(function(loggedIn) {
if (next.authenticate && !loggedIn) {
//event.preventDefault();
$location.path('/login');
}
});
});
Although my approach seems to work fine, I'm unsure if these changes are the best solutions or if there are other alternatives available.