From d656ba7eba0c8b8439185191a1cb18f5c46c81bb Mon Sep 17 00:00:00 2001 From: Justin Edmund Date: Mon, 28 Feb 2022 13:30:26 -0800 Subject: [PATCH] Fix logout state bug Logging out didn't reset state, so the HeaderMenu still displayed the logged in menu --- components/TopHeader/index.tsx | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/components/TopHeader/index.tsx b/components/TopHeader/index.tsx index b9b5897c..eed02d45 100644 --- a/components/TopHeader/index.tsx +++ b/components/TopHeader/index.tsx @@ -5,7 +5,7 @@ import clonedeep from 'lodash.clonedeep' import { useSnapshot } from 'valtio' import api from '~utils/api' -import { accountState } from '~utils/accountState' +import { accountState, initialAccountState } from '~utils/accountState' import { appState, initialAppState } from '~utils/appState' import Header from '~components/Header' @@ -51,10 +51,15 @@ const TopHeader = () => { function logout() { removeCookie('user') - accountState.authorized = false + // Clean state + const resetState = clonedeep(initialAccountState) + Object.keys(resetState).forEach((key) => { + if (key !== 'language') + accountState[key] = resetState[key] + }) + appState.party.editable = false - // TODO: How can we log out without navigating to root router.push('/') return false }