You can use the resolve method of $routeProvider to check for a logged in user before the view even loads. If unauthenticated you can raise an arbitrary event that another part of your app listens to and redirects the user to a log in view
$routeProvider.when('/edit/:pk',{
templateUrl: base_dir + 'update.html',
controller: `enter code here`'editCtrl',
resolve: {
currentUser: function(MyUserAuthService, $rootScope) {
var u = MyUserAuthService.getCurrentUser();
if (u === null) $rootScope.$broadcast('noauth');
return u;
}
}
})
app.run(function($rootScope, $location) {
$rootScope.$on('noauth', function() {
$location.path('/loginpage');
});
});