Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
<!DOCTYPE html>
<meta http-equiv="content-type" content="text/html;charset=windows-1252">
<title>Page Title</title>
var loginSession = localStorage.getItem('loginSession');
//Sample Login Function
function login(){
//Set login session = 1 after a successful login
localStorage.setItem('loginSession', 1);
//Sample Logout Function
function logout(){
//Set login session = 0 after a successful logout
localStorage.setItem('loginSession', 0);
function checkSession(){
var loginSession = localStorage.getItem('loginSession');
if(parseInt(loginSession) !== 1){
alert('Logged Out');
console.log("Session Status: LoggedOut");
console.log("Session Status: LoggedIn");
//Check session in every 300 ms
setTimeout("checkSession()", 500);
if(loginSession === null) login();
//intiate session check
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.