Commit e1b2dc9d authored by Saturnino Abril's avatar Saturnino Abril

fix redirect to select_team after logout by only loading "loadMe" when user...

fix redirect to select_team after logout by only loading "loadMe" when user has existing cookie and was_logged_in in the local storage (#2060)
parent 5a755d8f
......@@ -5,6 +5,8 @@ import {getClientConfig, getLicenseConfig} from 'mattermost-redux/actions/genera
import * as UserActions from 'mattermost-redux/actions/users';
import {Client4} from 'mattermost-redux/client';
import LocalStorageStore from 'stores/local_storage_store';
import {ActionTypes} from 'utils/constants';
export function loadMeAndConfig() {
......@@ -15,7 +17,7 @@ export function loadMeAndConfig() {
dispatch(getLicenseConfig()),
];
if (document.cookie.indexOf('MMUSERID=') > -1) {
if (document.cookie.indexOf('MMUSERID=') > -1 && LocalStorageStore.getWasLoggedIn()) {
promises.push(dispatch(UserActions.loadMe()));
}
......
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
// See LICENSE.txt for license information.
import thunk from 'redux-thunk';
import configureStore from 'redux-mock-store';
import * as Actions from 'actions/views/root';
const mockStore = configureStore([thunk]);
jest.mock('mattermost-redux/actions/general', () => {
const original = require.requireActual('mattermost-redux/actions/general');
return {
...original,
getClientConfig: () => ({type: 'MOCK_GET_CLIENT_CONFIG'}),
getLicenseConfig: () => ({type: 'MOCK_GET_LICENSE_CONFIG'}),
};
});
jest.mock('mattermost-redux/actions/users', () => {
const original = require.requireActual('mattermost-redux/actions/users');
return {
...original,
loadMe: () => ({type: 'MOCK_LOAD_ME'}),
};
});
describe('root view actions', () => {
const origCookies = document.cookie;
const origWasLoggedIn = localStorage.getItem('was_logged_in');
beforeAll(() => {
document.cookie = '';
localStorage.setItem('was_logged_in', '');
});
afterAll(() => {
document.cookie = origCookies;
localStorage.setItem('was_logged_in', origWasLoggedIn);
});
test('loadMeAndConfig, without user logged in', async () => {
const testStore = await mockStore({});
await testStore.dispatch(Actions.loadMeAndConfig());
expect(testStore.getActions()).toEqual([{type: 'MOCK_GET_CLIENT_CONFIG'}, {type: 'MOCK_GET_LICENSE_CONFIG'}]);
});
test('loadMeAndConfig, with user logged in', async () => {
const testStore = await mockStore({});
document.cookie = 'MMUSERID=userid';
localStorage.setItem('was_logged_in', 'true');
await testStore.dispatch(Actions.loadMeAndConfig());
expect(testStore.getActions()).toEqual([{type: 'MOCK_GET_CLIENT_CONFIG'}, {type: 'MOCK_GET_LICENSE_CONFIG'}, {type: 'MOCK_LOAD_ME'}]);
});
});
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