Purge state on logout, fixes #264

chats_paste
Alex Gleason 2020-09-27 19:09:35 -05:00
rodzic 5fa3d66a64
commit c05eb0120a
Nie znaleziono w bazie danych klucza dla tego podpisu
ID klucza GPG: 7211D1F99744FBB7
1 zmienionych plików z 25 dodań i 2 usunięć

Wyświetl plik

@ -1,4 +1,6 @@
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 timelines from './timelines';
import meta from './meta';
@ -48,7 +50,7 @@ import chat_messages from './chat_messages';
import chat_message_lists from './chat_message_lists';
import profile_hover_card from './profile_hover_card';
const reducers = {
const appReducer = combineReducers({
dropdown_menu,
timelines,
meta,
@ -97,6 +99,27 @@ const reducers = {
chat_messages,
chat_message_lists,
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;