when I change the cookie Expires / Max-Age to previous then current time from chrome dev tools application

1k Views Asked by At

I opened the chrome dev tool and from application Cookies, I changed the Cookie Expires / Max-Age to previous time then current time.

My question is when i change the Expires / Max-Age, its instantly reflecting and logged-out from website.

if logout functionality implemented at code level then how can we listen for cookie change and how can we achieve this functionality?

1

There are 1 best solutions below

0
Jaisa Ram On BEST ANSWER

I got it from What do browsers do with expired cookies?

and from

var checkCookie = function() {

var lastCookie = document.cookie; // 'static' memory between function calls

return function() {

    var currentCookie = document.cookie;

    if (currentCookie != lastCookie) {

        // something useful like parse cookie, run a callback fn, etc.

        lastCookie = currentCookie; // store latest cookie

    }
};
}();

window.setInterval(checkCookie, 100); // run every 100 ms