Skip to content

Commit

Permalink
Merge pull request #883 from pradnya-orchestral/OWASP_tokenexpiration
Browse files Browse the repository at this point in the history
logout action should logout user from all tabs
  • Loading branch information
m4dcoder authored May 11, 2021
2 parents 3d91f51 + 545aad9 commit 25b3b8c
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 25b3b8c

Please sign in to comment.