简体   繁体   中英

calling localStorage.clear() If user not engaged on application for the some duration

I'm new to Angular 6 and I did one pilot application with angular and I'm storing login credentials in local storage for the user authentication. now I want to call localStorage.clear() method when the user has not performed any action on my application in the delay of 30 minutes. Is it correct process to do? or else any other possibilities?

You can't. When do items in HTML5 local storage expire? The only thing you can do is set the delete statement in a timeout of 1 hour. This requires the user to stay on your page or the timeout won't be executed.

You can also set an expiration field. When the user revisits your site, check the expiration and delete the storage on next visit as the first thing you do.

No, this is not a good professional Practice. There is no sense to remove the user's credential from local storage. you should clear when the user is gonna log out. But at some points, it could be achieved to make a session log out automatically.

setTimeout(logout(){ alert("Hello"); }, 1800000);
logout(){
     localstorage.clear('user');
}

You can achieve by this.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM