Move session tokens list into security reducer
This commit is contained in:
parent
6b8fbbff47
commit
60a3a5b403
4 changed files with 25 additions and 11 deletions
|
@ -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)
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -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
|
||||
|
|
21
app/soapbox/reducers/security.js
Normal file
21
app/soapbox/reducers/security.js
Normal file
|
@ -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;
|
||||
}
|
||||
};
|
Loading…
Reference in a new issue