Fixed IE11 tabs preventing themselves from logging out
Этот коммит содержится в:
@@ -1,6 +1,8 @@
|
|||||||
// Copyright (c) 2015 Mattermost, Inc. All Rights Reserved.
|
// Copyright (c) 2015 Mattermost, Inc. All Rights Reserved.
|
||||||
// See License.txt for license information.
|
// See License.txt for license information.
|
||||||
|
|
||||||
|
import {generateId} from '../utils/utils.jsx';
|
||||||
|
|
||||||
function getPrefix() {
|
function getPrefix() {
|
||||||
if (global.window.mm_user) {
|
if (global.window.mm_user) {
|
||||||
return global.window.mm_user.id + '_';
|
return global.window.mm_user.id + '_';
|
||||||
@@ -26,6 +28,7 @@ class BrowserStoreClass {
|
|||||||
this.clearAll = this.clearAll.bind(this);
|
this.clearAll = this.clearAll.bind(this);
|
||||||
this.checkedLocalStorageSupported = '';
|
this.checkedLocalStorageSupported = '';
|
||||||
this.signalLogout = this.signalLogout.bind(this);
|
this.signalLogout = this.signalLogout.bind(this);
|
||||||
|
this.isSignallingLogout = this.isSignallingLogout.bind(this);
|
||||||
|
|
||||||
var currentVersion = sessionStorage.getItem('storage_version');
|
var currentVersion = sessionStorage.getItem('storage_version');
|
||||||
if (currentVersion !== global.window.mm_config.Version) {
|
if (currentVersion !== global.window.mm_config.Version) {
|
||||||
@@ -113,11 +116,19 @@ class BrowserStoreClass {
|
|||||||
|
|
||||||
signalLogout() {
|
signalLogout() {
|
||||||
if (this.isLocalStorageSupported()) {
|
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__');
|
localStorage.removeItem('__logout__');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
isSignallingLogout(logoutId) {
|
||||||
|
return logoutId === sessionStorage.getItem('__logout__');
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Preforms the given action on each item that has the given prefix
|
* Preforms the given action on each item that has the given prefix
|
||||||
* Signature for action is action(key, value)
|
* Signature for action is action(key, value)
|
||||||
@@ -151,7 +162,14 @@ class BrowserStoreClass {
|
|||||||
}
|
}
|
||||||
|
|
||||||
clear() {
|
clear() {
|
||||||
|
// don't clear the logout id so IE11 can tell which tab sent a logout request
|
||||||
|
const logoutId = sessionStorage.getItem('__logout__');
|
||||||
|
|
||||||
sessionStorage.clear();
|
sessionStorage.clear();
|
||||||
|
|
||||||
|
if (logoutId) {
|
||||||
|
sessionStorage.setItem('__logout__', logoutId);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
clearAll() {
|
clearAll() {
|
||||||
@@ -185,3 +203,4 @@ class BrowserStoreClass {
|
|||||||
|
|
||||||
var BrowserStore = new BrowserStoreClass();
|
var BrowserStore = new BrowserStoreClass();
|
||||||
export default BrowserStore;
|
export default BrowserStore;
|
||||||
|
window.BrowserStore = BrowserStore;
|
||||||
|
|||||||
@@ -57,7 +57,13 @@
|
|||||||
|
|
||||||
$(function () {
|
$(function () {
|
||||||
$(window).bind('storage', function (e) {
|
$(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');
|
console.log('detected logout from a different tab');
|
||||||
window.location.href = '/' + window.mm_team.name;
|
window.location.href = '/' + window.mm_team.name;
|
||||||
}
|
}
|
||||||
|
|||||||
Ссылка в новой задаче
Block a user