Commit 34780f3a authored by Joram Wilander's avatar Joram Wilander Committed by Corey Hulen
Browse files

Refresh login page if server version of client doesn't match browser version of client (#3004)

parent 2ccf5bba
......@@ -9,6 +9,7 @@ import * as GlobalActions from 'action_creators/global_actions.jsx';
import UserStore from 'stores/user_store.jsx';
import Client from 'utils/web_client.jsx';
import * as AsyncClient from 'utils/async_client.jsx';
import * as TextFormatting from 'utils/text_formatting.jsx';
import * as Utils from 'utils/utils.jsx';
......@@ -44,6 +45,8 @@ export default class Login extends React.Component {
if (UserStore.getCurrentUser()) {
browserHistory.push('/select_team');
}
AsyncClient.checkVersion();
}
preSubmit(e) {
......
......@@ -24,6 +24,7 @@ import * as AsyncClient from 'utils/async_client.jsx';
import ChannelStore from 'stores/channel_store.jsx';
import ErrorStore from 'stores/error_store.jsx';
import TeamStore from 'stores/team_store.jsx';
import BrowserStore from 'stores/browser_store.jsx';
import * as Utils from 'utils/utils.jsx';
import Client from 'utils/web_client.jsx';
......@@ -101,9 +102,10 @@ function preRenderSetup(callwhendone) {
}
);
// Make sure the websockets close
// Make sure the websockets close and reset version
$(window).on('beforeunload',
() => {
BrowserStore.setLastServerVersion('');
Websockets.close();
}
);
......
......@@ -158,6 +158,7 @@ class BrowserStoreClass {
clear() {
// don't clear the logout id so IE11 can tell which tab sent a logout request
const logoutId = sessionStorage.getItem('__logout__');
const serverVersion = this.getLastServerVersion();
sessionStorage.clear();
localStorage.clear();
......@@ -165,6 +166,10 @@ class BrowserStoreClass {
if (logoutId) {
sessionStorage.setItem('__logout__', logoutId);
}
if (serverVersion) {
this.setLastServerVersion(serverVersion);
}
}
clearAll() {
......
......@@ -47,7 +47,21 @@ function isCallInProgress(callName) {
return true;
}
export function getChannels(checkVersion) {
export function checkVersion() {
var serverVersion = Client.getServerVersion();
if (serverVersion !== BrowserStore.getLastServerVersion()) {
if (!BrowserStore.getLastServerVersion() || BrowserStore.getLastServerVersion() === '') {
BrowserStore.setLastServerVersion(serverVersion);
} else {
BrowserStore.setLastServerVersion(serverVersion);
window.location.reload(true);
console.log('Detected version update refreshing the page'); //eslint-disable-line no-console
}
}
}
export function getChannels(doVersionCheck) {
if (isCallInProgress('getChannels')) {
return null;
}
......@@ -58,18 +72,8 @@ export function getChannels(checkVersion) {
(data) => {
callTracker.getChannels = 0;
if (checkVersion) {
var serverVersion = Client.getServerVersion();
if (serverVersion !== BrowserStore.getLastServerVersion()) {
if (!BrowserStore.getLastServerVersion() || BrowserStore.getLastServerVersion() === '') {
BrowserStore.setLastServerVersion(serverVersion);
} else {
BrowserStore.setLastServerVersion(serverVersion);
window.location.reload(true);
console.log('Detected version update refreshing the page'); //eslint-disable-line no-console
}
}
if (doVersionCheck) {
checkVersion();
}
AppDispatcher.handleServerAction({
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment