I am creating project using angular. In my project i need to clear the session when user close the browser. I am doing this with below code
@HostListener('window:beforeunload')
async ngOnDestroy()
{
await this.someservice.logout.subscribe();
debugger;
}
But the problem is this api call never completed and session is not clearing.
I have something a little different for when user closes the browser in order to clear out the localStorage. I am not using the var event but kept it just so I could see and play around with what does get passed in.
@HostListener('window:beforeunload', ['$event'])
unloadHandler(event: Event)
{
localStorage.removeItem('storageName');
}
I have not had any issues with the above clearing out values.