I am storing one session value on local storage on angular 4 app using the below code.
this.http.post('http://localhost/salesneuronver4/Login/api/rest/Login/',value,
{ headers: this.headers}).map((res: Response) => res.json())
.subscribe(
res => { this.resnonseValue = res;
if(this.resnonseValue.status == 'success'){
this.getCookie();
// here I am storing session value
localStorage.setItem('userSession', this.resnonseValue.session_id);
// and its stored for current browser session
this.router.navigate(['/home']);
return false;
}else if(this.resnonseValue.status == 'expired'){
this.router.navigate(['/login']);
return false;
}
else{
this.errorMsg = this.resnonseValue.status;
}
},
err =>console.error(err)
);
}
Now When I close the browser tab or whole browser, the locally stored item userSesssion is lost. How to keep it persistent until the user has logged out?