Cover all AJAX calls .... when an AJAX call is done on your site that results in a 401 or 403, redirect the user to either the login page or an access denied page.
$.ajaxSetup({
statusCode: {
401: function(){
// Redirec the to the login page.
showLoginButton();
window.location.replace('/#login');