I have been working on implementing user authentication in my angular application. I implemented in a way that stores the token in local storage.
This is my code that is executed when a user has entered user credentials and pressed submit.
this.http.post('http://localhost:3000/users/login', this.user).subscribe(data => {
if (data['token']) {
localStorage.setItem('mean-token', data['token']);
location.reload();
this.router.navigate(['/']);
}
});
My application stores the token in the local storage and the token does not get deleted when the browser is closed. I want the token to be deleted when the browser is closed. How can I do that?
Question update: I understand that I need to store the data in session storage instead of local storage, but I have not been able to find how to do that in Angular 4. I would like to know how it is done in development with Angular 4.