Reputation: 3
I am new to angular 4 I have created one application using angular 4 where I have a login page and home page.When I log in with my credentials I will navigate to home page.
If I my application is opened in multiple tabs when I log out from one tab any click on other tab in application should redirect to login page as it happens in gmail.
Can any one please help me on this.Thanks in advance.
Upvotes: 0
Views: 4013
Reputation: 3342
In case you store token/login info in the local storage, you can listen to changes like that:
window.addEventListener('storage', (event) => {
// there is a problem with IE (in all other browsers event not emitted in current window)
// so need to check that it is the other tab that emitted event
// and avoid infinite loop
if (!document.hasFocus() && event.key === environment.localStorageTokenKey) {
// do stuff here
window.location.pathname = '/';
}
}, false);
Upvotes: 0
Reputation: 169
Solution:
Please maintain a authentication token, it will help you. It is not related to Angular 4
Example:
This is the simple solution for your question
Upvotes: 0
Reputation: 657476
You can send a request to the server to invalidate the authentication token (not related to Angular) and all tabs need to regularly check on the server if their token is still valid and log out themselves if not.
Upvotes: 0