From 38399858b522eb57e0aec2444105349d6d94357f Mon Sep 17 00:00:00 2001 From: Valerie Pomerleau Date: Wed, 17 Jul 2024 15:52:57 -0700 Subject: [PATCH] fix(settings): Handle multiple signins to settings Because: * If multiple accounts were signed in on different tabs, operations could be applied to the wrong account * Current account uid was not correctly updating to reflect the account in use in the focused tab This commit: * On tab focus, check if the account uid matches the current account uid. If not, update current account uid. * Only check for destroyed session after updating the current account uid to ensure the correct session is signed out on tab focus. Closes #FXA-9984 --- packages/fxa-settings/src/components/Settings/index.tsx | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/packages/fxa-settings/src/components/Settings/index.tsx b/packages/fxa-settings/src/components/Settings/index.tsx index 109c9fb121..ff7b3e505d 100644 --- a/packages/fxa-settings/src/components/Settings/index.tsx +++ b/packages/fxa-settings/src/components/Settings/index.tsx @@ -31,6 +31,8 @@ import PageRecentActivity from './PageRecentActivity'; import PageRecoveryKeyCreate from './PageRecoveryKeyCreate'; import { hardNavigate } from 'fxa-react/lib/utils'; import { SettingsIntegration } from './interfaces'; +import { currentAccount } from '../../lib/cache'; +import { setCurrentAccount } from '../../lib/storage-utils'; export const Settings = ({ integration, @@ -38,6 +40,7 @@ export const Settings = ({ const config = useConfig(); const { metricsEnabled, hasPassword } = useAccount(); const session = useSession(); + const account = useAccount(); useEffect(() => { if (config.metrics.navTiming.enabled && metricsEnabled) { @@ -51,13 +54,16 @@ export const Settings = ({ useEffect(() => { function handleWindowFocus() { + if (account.uid !== currentAccount()?.uid) { + setCurrentAccount(account.uid); + } if (session.isDestroyed) { hardNavigate('/'); } } window.addEventListener('focus', handleWindowFocus); return () => window.removeEventListener('focus', handleWindowFocus); - }, [session]); + }, [account, session]); const { loading, error } = useInitialSettingsState();