Refresh the page under more general conditions

merge-requests/451/head
Alex Gleason 2021-03-25 15:59:09 -05:00
rodzic 6ead42b06d
commit 659cee1c49
Nie znaleziono w bazie danych klucza dla tego podpisu
ID klucza GPG: 7211D1F99744FBB7
2 zmienionych plików z 30 dodań i 11 usunięć

Wyświetl plik

@ -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);
}
};

Wyświetl plik

@ -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) => {