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


    //check if expired session then simply rediect to login
      $window.location.href = baseUrl + 'Account/Login';

Must see this Angular Cookies FAQs


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 Tech Blog - https://www.code-sample.com/
My Books - Book 1 and Book 2

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