如何重定向的cookie在角JS到期后登录页面? [英] How to redirect to login page after cookie expires in Angular JS?

查看:324
本文介绍了如何重定向的cookie在角JS到期后登录页面?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有下面这段code的其中用户存储在cookie中。 Cookie的过期时间也设置。用户页面仍然显示即使在饼干已经过期。

  VAR过期=新的日期();
             expired.setTime(expired.getTime()+(60 * 1000));
             $ cookieStore.put(用户,user.username,{到期:到期});


解决方案

  VAR过期=新的日期();
             expired.setTime(expired.getTime()+(60 * 1000));
             $ cookieStore.put(用户,user.username,{到期:到期});
             $超时(函数(){
                 如果(!$ cookieStore.get(用户)){
                 $ window.location.href ='redirectlink';
}
},60);

I have the following piece of code where the user is stored in the cookie. The expiry time for the cookie is also set. The user page is still showing even after the cookie has expired.

             var expired = new Date();
             expired.setTime(expired.getTime() + (60*1000));
             $cookieStore.put('user', user.username, {expires : expired });

解决方案

     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);

这篇关于如何重定向的cookie在角JS到期后登录页面?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆