Answer the question
In order to leave comments, you need to log in
How to monitor cookie expiration without reloading the page?
I write a token in cookies, and give it the same expiration date as on the server, but it is reset only after the page is reloaded, but do I need to always check the expiration date by default? How to be?
Code after the config in the
.run() block
var expireDate = new Date();
expireDate.setTime(expireDate.getTime() + (4 * 60 * 1000));
$cookies.put('token', token, {'expires': expireDate});
if($cookies.get('token')){
$rootScope.token = $cookies.get('token');
$rootScope.isLogin = true;
console.log($rootScope.token);
} else{
$rootScope.logout();
console.log('Токен просрочен');
}
Answer the question
In order to leave comments, you need to log in
Check the information on the server on each request, and if the token is not active - return 401 and redirect to logout
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question