diff --git a/sites/org/hooks/useApp.mjs b/sites/org/hooks/useApp.mjs index 7ec5fa32e79..c90e6046bdf 100644 --- a/sites/org/hooks/useApp.mjs +++ b/sites/org/hooks/useApp.mjs @@ -95,6 +95,9 @@ const toastMethods = (t) => ({ }, }) +// Make it possible to always check for app.account.username +const noAccount = { username: false } + /* * The actual hook */ @@ -104,7 +107,7 @@ export function useApp({ bugsnag }) { const { t } = useTranslation(['toast']) // Persistent state - const [account, setAccount, accountReady] = useLocalStorage('account', { username: false }) + const [account, setAccount, accountReady] = useLocalStorage('account', noAccount) const [token, setToken] = useLocalStorage('token', null) const [theme, setTheme] = useTheme() @@ -155,6 +158,11 @@ export function useApp({ bugsnag }) { return id } + // Clear user data (when loggin in as a different user, this gets called) + const clear = () => { + setAccount({ username: false }) + } + return { // Static vars site: 'org', @@ -188,6 +196,7 @@ export function useApp({ bugsnag }) { stopLoading: () => setLoading(false), updateNavigation, setModal, + clear, // State handlers togglePrimaryMenu, diff --git a/sites/shared/hooks/useLocalStorage.mjs b/sites/shared/hooks/useLocalStorage.mjs index f7fcd502c99..1730c2e33d4 100644 --- a/sites/shared/hooks/useLocalStorage.mjs +++ b/sites/shared/hooks/useLocalStorage.mjs @@ -32,7 +32,7 @@ export function useLocalStorage(key, initialValue) { } catch (error) { console.log(error) } - }, []) // The linter will hate this, but this was cleared to stop a render loop + }, [setReady, setValue, key, initialValue]) return [storedValue, setValue, ready] }