I've added this module to my app: https://github.com/witoldsz/angular-http-auth/blob/gh-pages/lib/http-auth-interceptor.js
It broadcasts a message on 401 responses, very handy! Just not sure how I can make my $routeProvider listen for the $rootscope.$broadcast. I'd like to redirect to the sign-in page on 401s.
My $routeProvide looks like this:
var app = angular.module('demoApp', ['http-auth-interceptor','tastypieModule'])
.config(function($routeProvider) { $routeProvider.
when('/', {controller:HomeCrtl, templateUrl:'partials/home.html'}).
when('/sign-in', {controller:SiginInCtrl, templateUrl:'partials/sign-in.html'}).
otherwise({redirectTo:'/'});
})
You wouldn't make your $routeProvider listen for it. You would simply listen for it in your controller, and then use $location to send your application to the appropriate route.
app.controller('MainAppCtrl', function($scope, $rootScope, $location) {
$rootScope.$on('event:auth-loginConfirmed', function(){
$location.path('/');
});
});
EDIT: As you likely have a lot of controllers, you'd want to have a parent controller that wraps your ngView...
<div ng-controller="MainAppCtrl">
<div ng-view>
</div>
</div>
The above controller will now be present for all views, and is sure to register your listener.