In AngularJS 1.* there are two providers that arevery useful, $idleProvider
and $keepaliveProvider
. I used these to handle session timeouts and automatically logout user's in previous project's. We are starting a new project now from the group up with Angular2 and I want to know if there is a plan for having similar support to these? Ideally we could have a mechanism that automatically logs out the user from the client. Here is the snippet of the source from how we accomplished this in AngularJS -- how can this be done with Angular2?
// Configure Idle Session Timeout
userModule.config([
'KeepaliveProvider', 'IdleProvider',
($keepaliveProvider, $idleProvider) => {
var str = $('#IdleSessionTimeout').text();
var idleTimeOut = parseInt(str);
var interval = 60;
if (isNaN(idleTimeOut)) {
idleTimeOut = 20;
interval = 10;
} else {
idleTimeOut *= 60; // Convert minutes -> seconds
}
$idleProvider.idle(idleTimeOut);
// If we ever want to warn user they are about to timeout
//$idleProvider.timeout(5);
$keepaliveProvider.interval(interval);
}
]);
userModule.run(($rootScope) => {
$rootScope.$on('IdleTimeout', () => {
// On timeout, end the user session by redirecting to logout
var url = window.location.href;
url = url.replace(/\/\#.*$/, "/Account/Logout");
window.location.href = url;
});
});
// Activate Timeout Monitoring
userModule.run(['Idle', ($idle) => {
$idle.watch();
}]);
Please help...