[英]How to redirect to login page after cookie expires in Angular JS?
I have the following piece of code where the user is stored in the cookie. 我有以下一段用户存储在cookie中的代码。 The expiry time for the cookie is also set.
Cookie的到期时间也已设置。 The user page is still showing even after the cookie has expired.
即使Cookie过期后,用户页面仍会显示。
var expired = new Date();
expired.setTime(expired.getTime() + (60*1000));
$cookieStore.put('user', user.username, {expires : expired });
What about on page loading, you get the expiration date and use a setTimeout()
to refresh it or redirect your user on an other page ? 那么在页面加载中,您将获得到期日期并使用
setTimeout()
刷新它或将您的用户重定向到另一页面上呢?
Some ressources about settimeout : 有关settimeout的一些资源:
Best would be to display 1 minutes before expiration date a popup inviting user to update it or perform an action. 最好是在到期日期前1分钟显示一个弹出窗口,邀请用户进行更新或执行操作。
var expired = new Date();
expired.setTime(expired.getTime() + (60*1000));
$cookieStore.put('user', user.username, {expires : expired });
$timeout(function(){
if(!$cookieStore.get('user')){
$window.location.href = 'redirectlink';
}
},60);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.