From 74f74d29fcc30333fd19bd0541d4d3fdb75f53ea Mon Sep 17 00:00:00 2001 From: Alex Gleason Date: Fri, 11 Oct 2024 15:16:10 -0500 Subject: [PATCH] Refresh when logging out by default --- src/actions/auth.ts | 4 ++-- src/reducers/auth.ts | 4 ++-- src/reducers/index.ts | 29 +---------------------------- 3 files changed, 5 insertions(+), 32 deletions(-) diff --git a/src/actions/auth.ts b/src/actions/auth.ts index f84e1df40..e1e5fddfe 100644 --- a/src/actions/auth.ts +++ b/src/actions/auth.ts @@ -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); }); diff --git a/src/reducers/auth.ts b/src/reducers/auth.ts index af980a3a2..f066f3dbb 100644 --- a/src/reducers/auth.ts +++ b/src/reducers/auth.ts @@ -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(); } }; diff --git a/src/reducers/index.ts b/src/reducers/index.ts index a6df8e026..4534812dd 100644 --- a/src/reducers/index.ts +++ b/src/reducers/index.ts @@ -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; - -// Clear the state (mostly) when the user logs out -const logOut = (state: AppState): ReturnType => { - 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); \ No newline at end of file