Refresh the page under more general conditions
This commit is contained in:
parent
6ead42b06d
commit
659cee1c49
2 changed files with 30 additions and 11 deletions
|
@ -124,17 +124,36 @@ const reducer = (state, action) => {
|
|||
}
|
||||
};
|
||||
|
||||
const maybeReload = (oldState, state, action) => {
|
||||
if (action.type === SWITCH_ACCOUNT) {
|
||||
if (location.pathname === '/auth/sign_in') {
|
||||
location.replace('/');
|
||||
} else {
|
||||
location.reload();
|
||||
}
|
||||
}
|
||||
// The user has a token stored in their browser
|
||||
const canAuth = state => {
|
||||
state = maybeShiftMe(state);
|
||||
const me = state.get('me');
|
||||
const token = state.getIn(['users', me, 'access_token']);
|
||||
return typeof token === 'string';
|
||||
};
|
||||
|
||||
if (action.type === VERIFY_CREDENTIALS_FAIL && state.get('me') !== oldState.get('me')) {
|
||||
location.reload();
|
||||
// Reload, but redirect home if the user is already logged in
|
||||
const reload = state => {
|
||||
if (location.pathname === '/auth/sign_in' && canAuth(state)) {
|
||||
return location.replace('/');
|
||||
} else {
|
||||
return location.reload();
|
||||
}
|
||||
};
|
||||
|
||||
// `me` has changed from one valid ID to another
|
||||
const userSwitched = (oldState, state) => {
|
||||
const validMe = state => typeof state.get('me') === 'string';
|
||||
|
||||
const stillValid = validMe(oldState) && validMe(state);
|
||||
const didChange = oldState.get('me') !== state.get('me');
|
||||
|
||||
return stillValid && didChange;
|
||||
};
|
||||
|
||||
const maybeReload = (oldState, state, action) => {
|
||||
if (userSwitched(oldState, state)) {
|
||||
reload(state);
|
||||
}
|
||||
};
|
||||
|
||||
|
|
|
@ -109,7 +109,7 @@ const appReducer = combineReducers({
|
|||
|
||||
// Clear the state (mostly) when the user logs out
|
||||
const logOut = (state = ImmutableMap()) => {
|
||||
const whitelist = ['instance', 'soapbox', 'custom_emojis'];
|
||||
const whitelist = ['instance', 'soapbox', 'custom_emojis', 'auth'];
|
||||
|
||||
return ImmutableMap(
|
||||
whitelist.reduce((acc, curr) => {
|
||||
|
|
Loading…
Reference in a new issue