Purge state on logout, fixes #264

This commit is contained in:
Alex Gleason 2020-09-27 19:09:35 -05:00
parent 5fa3d66a64
commit c05eb0120a
No known key found for this signature in database
GPG key ID: 7211D1F99744FBB7

View file

@ -1,4 +1,6 @@
import { combineReducers } from 'redux-immutable'; import { combineReducers } from 'redux-immutable';
import { Map as ImmutableMap } from 'immutable';
import { AUTH_LOGGED_OUT } from 'soapbox/actions/auth';
import dropdown_menu from './dropdown_menu'; import dropdown_menu from './dropdown_menu';
import timelines from './timelines'; import timelines from './timelines';
import meta from './meta'; import meta from './meta';
@ -48,7 +50,7 @@ import chat_messages from './chat_messages';
import chat_message_lists from './chat_message_lists'; import chat_message_lists from './chat_message_lists';
import profile_hover_card from './profile_hover_card'; import profile_hover_card from './profile_hover_card';
const reducers = { const appReducer = combineReducers({
dropdown_menu, dropdown_menu,
timelines, timelines,
meta, meta,
@ -97,6 +99,27 @@ const reducers = {
chat_messages, chat_messages,
chat_message_lists, chat_message_lists,
profile_hover_card, profile_hover_card,
});
// Clear the state (mostly) when the user logs out
const logOut = (state = ImmutableMap()) => {
const whitelist = ['instance', 'soapbox', 'custom_emojis'];
return ImmutableMap(
whitelist.reduce((acc, curr) => {
acc[curr] = state.get(curr);
return acc;
}, {})
);
}; };
export default combineReducers(reducers); const rootReducer = (state, action) => {
switch(action.type) {
case AUTH_LOGGED_OUT:
return appReducer(logOut(state), action);
default:
return appReducer(state, action);
}
};
export default rootReducer;