mirror of
https://github.com/mattermost/mattermost.git
synced 2025-02-25 18:55:24 -06:00
Fixed IE11 tabs preventing themselves from logging out
This commit is contained in:
@@ -1,6 +1,8 @@
|
||||
// Copyright (c) 2015 Mattermost, Inc. All Rights Reserved.
|
||||
// See License.txt for license information.
|
||||
|
||||
import {generateId} from '../utils/utils.jsx';
|
||||
|
||||
function getPrefix() {
|
||||
if (global.window.mm_user) {
|
||||
return global.window.mm_user.id + '_';
|
||||
@@ -26,6 +28,7 @@ class BrowserStoreClass {
|
||||
this.clearAll = this.clearAll.bind(this);
|
||||
this.checkedLocalStorageSupported = '';
|
||||
this.signalLogout = this.signalLogout.bind(this);
|
||||
this.isSignallingLogout = this.isSignallingLogout.bind(this);
|
||||
|
||||
var currentVersion = sessionStorage.getItem('storage_version');
|
||||
if (currentVersion !== global.window.mm_config.Version) {
|
||||
@@ -113,11 +116,19 @@ class BrowserStoreClass {
|
||||
|
||||
signalLogout() {
|
||||
if (this.isLocalStorageSupported()) {
|
||||
localStorage.setItem('__logout__', 'yes');
|
||||
// PLT-1285 store an identifier in session storage so we can catch if the logout came from this tab on IE11
|
||||
const logoutId = generateId();
|
||||
|
||||
sessionStorage.setItem('__logout__', logoutId);
|
||||
localStorage.setItem('__logout__', logoutId);
|
||||
localStorage.removeItem('__logout__');
|
||||
}
|
||||
}
|
||||
|
||||
isSignallingLogout(logoutId) {
|
||||
return logoutId === sessionStorage.getItem('__logout__');
|
||||
}
|
||||
|
||||
/**
|
||||
* Preforms the given action on each item that has the given prefix
|
||||
* Signature for action is action(key, value)
|
||||
@@ -151,7 +162,14 @@ class BrowserStoreClass {
|
||||
}
|
||||
|
||||
clear() {
|
||||
// don't clear the logout id so IE11 can tell which tab sent a logout request
|
||||
const logoutId = sessionStorage.getItem('__logout__');
|
||||
|
||||
sessionStorage.clear();
|
||||
|
||||
if (logoutId) {
|
||||
sessionStorage.setItem('__logout__', logoutId);
|
||||
}
|
||||
}
|
||||
|
||||
clearAll() {
|
||||
@@ -185,3 +203,4 @@ class BrowserStoreClass {
|
||||
|
||||
var BrowserStore = new BrowserStoreClass();
|
||||
export default BrowserStore;
|
||||
window.BrowserStore = BrowserStore;
|
||||
|
||||
@@ -57,7 +57,13 @@
|
||||
|
||||
$(function () {
|
||||
$(window).bind('storage', function (e) {
|
||||
if (e.originalEvent.key === '__logout__') {
|
||||
// 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 (window.BrowserStore.isSignallingLogout(e.originalEvent.newValue)) {
|
||||
return;
|
||||
}
|
||||
|
||||
console.log('detected logout from a different tab');
|
||||
window.location.href = '/' + window.mm_team.name;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user