diff --git a/packages/nicolium/src/actions/auth.ts b/packages/nicolium/src/actions/auth.ts index 154dd6ac9..1af872aeb 100644 --- a/packages/nicolium/src/actions/auth.ts +++ b/packages/nicolium/src/actions/auth.ts @@ -288,13 +288,15 @@ interface SwitchAccountAction { account: Account; } -const switchAccount = (accountId: string) => (dispatch: AppDispatch) => { +const switchAccount = (accountId: string) => (dispatch: AppDispatch, getState: () => RootState) => { const account = selectAccount(accountId); if (!account) return; - // Clear all stored cache from React Query - queryClient.invalidateQueries(); - queryClient.clear(); + if (typeof getState().me === 'string' && getState().me !== account.id) { + // Clear all stored cache from React Query + queryClient.invalidateQueries(); + queryClient.clear(); + } return dispatch({ type: SWITCH_ACCOUNT, account }); }; diff --git a/packages/nicolium/src/features/ui/components/panels/sign-up-panel.tsx b/packages/nicolium/src/features/ui/components/panels/sign-up-panel.tsx index 655717874..6b76a0889 100644 --- a/packages/nicolium/src/features/ui/components/panels/sign-up-panel.tsx +++ b/packages/nicolium/src/features/ui/components/panels/sign-up-panel.tsx @@ -48,9 +48,8 @@ const SignUpPanel = () => { return account; }) .then((account: { id: string }) => { - if (typeof me === 'string') { - dispatch(switchAccount(account.id)); - } else { + dispatch(switchAccount(account.id)); + if (typeof me !== 'string') { setShouldRedirect(true); } }) diff --git a/packages/nicolium/src/pages/auth/login.tsx b/packages/nicolium/src/pages/auth/login.tsx index 1e7cbd92f..ce6e72c67 100644 --- a/packages/nicolium/src/pages/auth/login.tsx +++ b/packages/nicolium/src/pages/auth/login.tsx @@ -47,9 +47,8 @@ const LoginPage = () => { }) .then((account: { id: string }) => { closeModal(); - if (typeof me === 'string') { - dispatch(switchAccount(account.id)); - } else { + dispatch(switchAccount(account.id)); + if (typeof me !== 'string') { setShouldRedirect(true); } }) diff --git a/packages/nicolium/src/reducers/me.ts b/packages/nicolium/src/reducers/me.ts index d3b87558f..b30697dc6 100644 --- a/packages/nicolium/src/reducers/me.ts +++ b/packages/nicolium/src/reducers/me.ts @@ -3,6 +3,7 @@ import { AUTH_ACCOUNT_REMEMBER_SUCCESS, VERIFY_CREDENTIALS_SUCCESS, type AuthAction, + SWITCH_ACCOUNT, } from '@/actions/auth'; import { ME_FETCH_SUCCESS, @@ -38,6 +39,8 @@ const me = (state: Me = initialState, action: AuthAction | MeAction): Me => { return false; case ME_FETCH_FAIL: return handleForbidden(state, action.error as any); + case SWITCH_ACCOUNT: + return action.account.id; default: return state; }