After logging in and redirecting from one page to the mainpage, it appears that my rootscope is being reset. Below is the code for the redirect after successful login:
self.authUser = function() {
LoginService.authUser($scope.inputEmail, $scope.inputPassword, 'inf')
.then(function(d) {
$rootScope.authenticated = true;
$window.location.href = '/job';
}, function(errResponse) {
$scope.errorLogin = true;
$rootScope.authenticated = false;
});
};
Here is the code for the mainpage:
<script src="<c:url value="/resources/js/application.js"/>"></script>
<script src="<c:url value="/resources/js/service/main_service.js"/>"></script>
<script
src="<c:url value="/resources/js/controller/main_controller.js"/>"></script>
<title>Insert title here</title>
</head>
<body ng-app='application'>
<div class='container' ng-controller='MainController as ctrl'>
<span ng-show='authenticated'>lllllllllllllllloloooooo</span>
<button class="btn btn-lg btn-primary btn-block" ng-click='ctrl.authorize()'>Sign
in</button>
</div>
</body>
Upon successful login, the rootScope is set to true but resets when using $window.location.href. Is there a need to reauthenticate on every page load via a post response?
Edit: ngRoute
application.js
'use strict';
var App = angular.module('application', [ 'ngRoute', 'ngCookies' ]).config(
[ '$routeProvider', function($routeProvider) {
$routeProvider.when('/', {
templateUrl : '/job/',
controller : 'main_controller'
}).when('/login', {
templateUrl : '/job/login',
controller : 'login_controller'
}).otherwise({
redirectTo : '/'
});
} ]);
Tried $location.path("/"); $scope.$apply();
and $window.location.assign('/job');
also
$timeout(function () {
$location.path("/");
});
$location doesn't change page & $window refreshes my rootscope