简体   繁体   English

Cookie在Angular JS中过期后如何重定向到登录页面?

[英]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.

相关问题 会话过期后如何使整个页面重定向到登录在MVC中? - How to make entire page redirect to login after session expires in mvc? 如果在使用角度JS登录后单击后退按钮,如何重定向到主页? - How to redirect to home page if I click back button after login in angular JS? AngularJS:登录cookie过期时如何注销 - AngularJS: How to logout when login cookie expires 会话在AJAX中过期后,ASP.NET MVC重定向到登录页面 - ASP.NET MVC redirect to login page after session expires in AJAX Angular 登录成功后再次重定向到登录页面 - Angular redirect again to login page after successfully login 设置后cookie不会过期 - cookie not expires after set 在Vue JS中成功登录后如何重定向到仪表板组件页面(登录组件)? - How to redirect to the dashboard component page after login successfully(login component) in vue js? ReactJS成功登录后如何重定向到页面? - how to redirect to a page after successful login in ReactJS? 登录成功后如何重定向到仪表盘页面 - How to redirect to deshboard page after login successfull 成功登录后如何重新加载/重定向页面? - How to reload / redirect page after successful login?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM