Skip to content

Commit

Permalink
logout action should logout user from all tabs
Browse files Browse the repository at this point in the history
  • Loading branch information
pradnya-orchestral committed May 10, 2021
1 parent 3d91f51 commit 545aad9
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
5 changes: 5 additions & 0 deletions modules/st2-api/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -135,13 +135,18 @@ export class API {
server: this.server,
token: this.token,
}));
localStorage.setItem('logged_in',JSON.stringify({
loggedIn: true,
}));
}
}

disconnect() {
this.token = null;
this.server = null;
localStorage.removeItem('st2Session');
localStorage.removeItem('logged_in');

}

isConnected() {
Expand Down
17 changes: 17 additions & 0 deletions modules/st2-menu/menu.component.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,26 @@ export default class Menu extends React.Component {
style: componentStyle,
}

componentDidMount() {
window.addEventListener('storage', this.storageChange());
}

componentWillUnmount() {
window.removeEventListener('storage',this.storageChange());
}

docsLink = 'https://docs.stackstorm.com/'
supportLink = 'https://forum.stackstorm.com/'

storageChange () {
window.addEventListener('storage', (event) => {
if (event.key === 'logged_in' && (event.oldValue !== event.newValue)) {
api.disconnect();
window.location.reload();
}
});
}

handleDisconnect() {
api.disconnect();
window.location.reload();
Expand Down

0 comments on commit 545aad9

Please sign in to comment.