Reputation: 106
I'm working with Angular 4 project. I've the following scenario:
Once I'm logged-in using one user and I open up another tab and log-in using other user, the local storage authorization(Cookie) of previously logged-in user gets overridden with the that of newly logged-in user's. And hence I get unwanted behavior which kinda breaks the app functionality.
How to manage it? Do I need to make corrections from server-side or from Angular? It's a bit subjective question but I'd really appreciate some example reference or a practical implementation for the same.
Upvotes: 0
Views: 1229
Reputation: 378
Before calling login API you do like this
if ( entered username/passward === localStorage.getItem('user')) {
// allow him to next page
} else if(localStorage.getItem('user') === undefined) {
//call login API
//and store user credentials like this
localStorage.setItem('user', 'your value');
}else {
// show error message as already logged in
}
and once current user logged out clear local storage
localStorage.removeItem('user');
Upvotes: 1
Reputation: 6568
as per my consideration, if you are using local storage value for the logged purpose. so for every time user logged in or click on a login button or login process check, this local storage value is present or no. if it present don't allow opening your login page.
and don't forget to clear your local storage value when a user logs out.
Upvotes: 1