From c81efa0b4e11fc1d86c6b16efd8670cf29756d81 Mon Sep 17 00:00:00 2001 From: Corey Hulen Date: Fri, 6 Jan 2017 08:54:02 -0500 Subject: PLT-4758 fixing signaling of logout (#4984) --- webapp/components/root.jsx | 27 ++++++++++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) (limited to 'webapp/components/root.jsx') diff --git a/webapp/components/root.jsx b/webapp/components/root.jsx index be50c7d48..465df5d79 100644 --- a/webapp/components/root.jsx +++ b/webapp/components/root.jsx @@ -8,11 +8,12 @@ import Client from 'client/web_client.jsx'; import {IntlProvider} from 'react-intl'; import React from 'react'; - import FastClick from 'fastclick'; +import $ from 'jquery'; import {browserHistory} from 'react-router/es6'; import UserStore from 'stores/user_store.jsx'; +import BrowserStore from 'stores/browser_store.jsx'; export default class Root extends React.Component { constructor(props) { @@ -35,6 +36,30 @@ export default class Root extends React.Component { } /*eslint-enable */ + // Force logout of all tabs if one tab is logged out + $(window).bind('storage', (e) => { + // when one tab on a browser logs out, it sets __logout__ in localStorage to trigger other tabs to log out + if (e.originalEvent.key === '__logout__' && e.originalEvent.storageArea === localStorage && e.originalEvent.newValue) { + // make sure it isn't this tab that is sending the logout signal (only necessary for IE11) + if (BrowserStore.isSignallingLogout(e.originalEvent.newValue)) { + return; + } + + console.log('detected logout from a different tab'); //eslint-disable-line no-console + GlobalActions.emitUserLoggedOutEvent('/', false); + } + + if (e.originalEvent.key === '__login__' && e.originalEvent.storageArea === localStorage && e.originalEvent.newValue) { + // make sure it isn't this tab that is sending the logout signal (only necessary for IE11) + if (BrowserStore.isSignallingLogin(e.originalEvent.newValue)) { + return; + } + + console.log('detected login from a different tab'); //eslint-disable-line no-console + location.reload(); + } + }); + // Fastclick FastClick.attach(document.body); } -- cgit v1.2.3-1-g7c22