diff --git a/app/soapbox/features/security/index.js b/app/soapbox/features/security/index.js index f45416518..30c5e9686 100644 --- a/app/soapbox/features/security/index.js +++ b/app/soapbox/features/security/index.js @@ -63,9 +63,8 @@ const messages = defineMessages({ }); const mapStateToProps = state => ({ - backup_codes: state.getIn(['auth', 'backup_codes', 'codes']), settings: getSettings(state), - tokens: state.getIn(['auth', 'tokens']), + tokens: state.getIn(['security', 'tokens']), }); export default @connect(mapStateToProps) diff --git a/app/soapbox/reducers/auth.js b/app/soapbox/reducers/auth.js index 9518073c5..c36cf4ef5 100644 --- a/app/soapbox/reducers/auth.js +++ b/app/soapbox/reducers/auth.js @@ -3,17 +3,14 @@ import { AUTH_LOGGED_IN, AUTH_APP_AUTHORIZED, AUTH_LOGGED_OUT, - FETCH_TOKENS_SUCCESS, - REVOKE_TOKEN_SUCCESS, SWITCH_ACCOUNT, } from '../actions/auth'; -import { Map as ImmutableMap, List as ImmutableList, fromJS } from 'immutable'; +import { Map as ImmutableMap, fromJS } from 'immutable'; const initialState = ImmutableMap({ app: ImmutableMap(JSON.parse(localStorage.getItem('soapbox:auth:app'))), users: fromJS(JSON.parse(localStorage.getItem('soapbox:auth:users'))), me: localStorage.getItem('soapbox:auth:me'), - tokens: ImmutableList(), }); export default function auth(state = initialState, action) { @@ -30,11 +27,6 @@ export default function auth(state = initialState, action) { case AUTH_LOGGED_OUT: localStorage.removeItem('soapbox:auth:user'); return state.set('user', ImmutableMap()); - case FETCH_TOKENS_SUCCESS: - return state.set('tokens', fromJS(action.tokens)); - case REVOKE_TOKEN_SUCCESS: - const idx = state.get('tokens').findIndex(t => t.get('id') === action.id); - return state.deleteIn(['tokens', idx]); case SWITCH_ACCOUNT: localStorage.setItem('soapbox:auth:me', action.accountId); location.reload(); diff --git a/app/soapbox/reducers/index.js b/app/soapbox/reducers/index.js index 45ab583d0..116766fab 100644 --- a/app/soapbox/reducers/index.js +++ b/app/soapbox/reducers/index.js @@ -51,6 +51,7 @@ import chat_message_lists from './chat_message_lists'; import profile_hover_card from './profile_hover_card'; import backups from './backups'; import admin_log from './admin_log'; +import security from './security'; const appReducer = combineReducers({ dropdown_menu, @@ -103,6 +104,7 @@ const appReducer = combineReducers({ profile_hover_card, backups, admin_log, + security, }); // Clear the state (mostly) when the user logs out diff --git a/app/soapbox/reducers/security.js b/app/soapbox/reducers/security.js new file mode 100644 index 000000000..93f6fa632 --- /dev/null +++ b/app/soapbox/reducers/security.js @@ -0,0 +1,21 @@ +import { + FETCH_TOKENS_SUCCESS, + REVOKE_TOKEN_SUCCESS, +} from '../actions/auth'; +import { Map as ImmutableMap, List as ImmutableList, fromJS } from 'immutable'; + +const initialState = ImmutableMap({ + tokens: ImmutableList(), +}); + +export default function security(state = initialState, action) { + switch(action.type) { + case FETCH_TOKENS_SUCCESS: + return state.set('tokens', fromJS(action.tokens)); + case REVOKE_TOKEN_SUCCESS: + const idx = state.get('tokens').findIndex(t => t.get('id') === action.id); + return state.deleteIn(['tokens', idx]); + default: + return state; + } +};