$cookieStore in Angular

Redirect to login page after session expires AngularJs | $cookieStore

How to redirect to login page after session expires using $cookieStore?

A cookie is a small piece of data sent from a website and stored on the user's machine by the user's web browsers while the user is browsing.

In the below code, we are stored in the cookie’s expiry time. If the application cookie is expired the page will redirect to login or where you want to redirect this page.

As an Example,
var date = new Date();

//set expire time
date.setTime(date.getTime() + (60*1000));

//set expire time in te cookie store
$cookieStore.put('app_user'appUser.name, {expires : date });

$timeout(function(){

    //check if expired session then simply rediect to login
    if(!$cookieStore.get('app_user')){
      $window.location.href = baseUrl + 'Account/Login';
    }
},60);

Must see this Angular Cookies FAQs

ANIL SINGH

Anil Singh is an author, tech blogger, and software programmer. Book writing, tech blogging is something do extra and Anil love doing it. For more detail, kindly refer to this link..
My Blogs - https://code-sample.com and https://code-sample.xyz
My Book1 - BEST SELLING ANGULAR BOOK (INCLUDING ALL VERSIONS 2, 4, 5, 6, 7)
My Book2 - ANGULAR 2 INTERVIEW QUESTIONS BOOK - Both Books are Available on WorldWide.

www.code-sample.com/. Powered by Blogger.
^