我有以下代码,用户存储在cookie中。还设置了cookie的到期时间。即使cookie过期,用户页面仍然显示。
var expired = new Date();
expired.setTime(expired.getTime() + (60*1000));
$cookieStore.put('user', user.username, {expires : expired });
答案 0 :(得分:0)
如果在页面加载时,您会获得到期日期并使用setTimeout()
进行刷新或将用户重定向到其他页面上?
有关 settimeout 的一些资源:
最好是在到期日前1分钟显示弹出窗口,邀请用户更新或执行操作。
答案 1 :(得分:0)
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);