Refresh when logging out by default

environments/review-instance-h-clda5e/deployments/4891
Alex Gleason 2024-10-11 15:16:10 -05:00
rodzic 82731e633d
commit 74f74d29fc
Nie znaleziono w bazie danych klucza dla tego podpisu
ID klucza GPG: 7211D1F99744FBB7
3 zmienionych plików z 5 dodań i 32 usunięć

Wyświetl plik

@ -200,7 +200,7 @@ export const logIn = (username: string, password: string) =>
export const deleteSession = () =>
(dispatch: AppDispatch, getState: () => RootState) => api(getState).delete('/api/sign_out');
export const logOut = (refresh?: boolean) =>
export const logOut = (refresh = true) =>
(dispatch: AppDispatch, getState: () => RootState) => {
const state = getState();
const account = getLoggedInAccount(state);
@ -227,7 +227,7 @@ export const logOut = (refresh?: boolean) =>
localStorage.removeItem('soapbox:external:baseurl');
localStorage.removeItem('soapbox:external:scopes');
dispatch({ type: AUTH_LOGGED_OUT, account, standalone: refresh });
dispatch({ type: AUTH_LOGGED_OUT, account, refresh });
toast.success(messages.loggedOut);
});

Wyświetl plik

@ -378,10 +378,10 @@ const userSwitched = (oldState: State, state: State) => {
};
const maybeReload = (oldState: State, state: State, action: AnyAction) => {
const loggedOutStandalone = action.type === AUTH_LOGGED_OUT && action.standalone;
const shouldRefresh = action.type === AUTH_LOGGED_OUT && action.refresh;
const switched = userSwitched(oldState, state);
if (switched || loggedOutStandalone) {
if (switched || shouldRefresh) {
reload();
}
};

Wyświetl plik

@ -1,7 +1,5 @@
import { combineReducers } from '@reduxjs/toolkit';
import { AUTH_LOGGED_OUT } from 'soapbox/actions/auth';
import * as BuildConfig from 'soapbox/build-config';
import entities from 'soapbox/entity-store/reducer';
import accounts_meta from './accounts-meta';
@ -119,29 +117,4 @@ const reducers = {
user_lists,
};
const appReducer = combineReducers(reducers);
type AppState = ReturnType<typeof appReducer>;
// Clear the state (mostly) when the user logs out
const logOut = (state: AppState): ReturnType<typeof appReducer> => {
if (BuildConfig.NODE_ENV === 'production') {
location.href = '/login';
}
const newState = rootReducer(undefined, { type: '' });
const { instance, soapbox, custom_emojis, auth } = state;
return { ...newState, instance, soapbox, custom_emojis, auth };
};
const rootReducer: typeof appReducer = (state, action) => {
switch (action.type) {
case AUTH_LOGGED_OUT:
return appReducer(logOut(state as AppState), action);
default:
return appReducer(state, action);
}
};
export default appReducer;
export default combineReducers(reducers);