From 23a8676c19b2cea205aa0179fc581a98e7c66742 Mon Sep 17 00:00:00 2001 From: Thomas Hopkins Date: Fri, 21 Oct 2016 10:17:36 -0700 Subject: [PATCH] Fix: Clear stores when user logs out (#65) * Import missing action types for logout * Correctly destructure logout response from doFetchWithResponse * Return to SelectServer upon logout * Add todo regarding clearing clientConfig upon logout --- src/client/client.js | 2 +- src/components/logout.js | 2 +- src/reducers/channels.js | 3 ++- src/reducers/general.js | 2 ++ src/reducers/login.js | 3 ++- src/reducers/posts.js | 3 ++- src/reducers/teams.js | 3 ++- 7 files changed, 12 insertions(+), 6 deletions(-) diff --git a/src/client/client.js b/src/client/client.js index ad55c9391..08f2884ad 100644 --- a/src/client/client.js +++ b/src/client/client.js @@ -183,7 +183,7 @@ export default class Client { } logout = async () => { - const response = await this.doFetchWithResponse( + const {response} = await this.doFetchWithResponse( `${this.getUsersRoute()}/logout`, {method: 'post'} ); diff --git a/src/components/logout.js b/src/components/logout.js index 3a5459fa5..65be3d53f 100644 --- a/src/components/logout.js +++ b/src/components/logout.js @@ -19,7 +19,7 @@ class Logout extends Component { componentWillReceiveProps(newProps) { if (this.props.logout.status === 'fetching' && newProps.logout.status === 'fetched') { - Routes.popTo('goToLogin'); + Routes.popTo('goToSelectServer'); } } diff --git a/src/reducers/channels.js b/src/reducers/channels.js index 7b0886b05..6704231c8 100644 --- a/src/reducers/channels.js +++ b/src/reducers/channels.js @@ -1,5 +1,6 @@ import _ from 'lodash'; -import {ChannelsTypes as types} from 'constants'; +import {ChannelsTypes, LogoutTypes} from 'constants'; +const types = {...ChannelsTypes, ...LogoutTypes}; export const initState = { status: 'not fetched', diff --git a/src/reducers/general.js b/src/reducers/general.js index e4e1ca6af..49418436c 100644 --- a/src/reducers/general.js +++ b/src/reducers/general.js @@ -7,6 +7,8 @@ import {GeneralTypes as types} from 'constants'; export const initState = initialState(); +// TODO: clientConfig should be cleared when the user logs out. +// We can't do so until it's extracted into its own store with more reducers export function clientConfig(state = initState, action) { return handle( types.CLIENT_CONFIG_REQUEST, diff --git a/src/reducers/login.js b/src/reducers/login.js index 59040d0a1..4b3ed9cf4 100644 --- a/src/reducers/login.js +++ b/src/reducers/login.js @@ -1,7 +1,8 @@ // Copyright (c) 2016 Mattermost, Inc. All Rights Reserved. // See License.txt for license information. -import {LoginTypes as types} from 'constants'; +import {LoginTypes, LogoutTypes} from 'constants'; +const types = {...LoginTypes, ...LogoutTypes}; export const initState = { status: 'not fetched', diff --git a/src/reducers/posts.js b/src/reducers/posts.js index c79858705..417ec3346 100644 --- a/src/reducers/posts.js +++ b/src/reducers/posts.js @@ -1,4 +1,5 @@ -import {PostsTypes as types} from 'constants'; +import {PostsTypes, LogoutTypes} from 'constants'; +const types = {...PostsTypes, ...LogoutTypes}; export const initState = { status: 'not fetched', diff --git a/src/reducers/teams.js b/src/reducers/teams.js index c4cd7d17f..a4b4ac180 100644 --- a/src/reducers/teams.js +++ b/src/reducers/teams.js @@ -1,4 +1,5 @@ -import {TeamsTypes as types} from 'constants'; +import {TeamsTypes, LogoutTypes} from 'constants'; +const types = {...TeamsTypes, ...LogoutTypes}; export const initState = { status: 'not fetched',