Fix logout state bug

Logging out didn't reset state, so the HeaderMenu still displayed the logged in menu
This commit is contained in:
Justin Edmund 2022-02-28 13:30:26 -08:00
parent 26fa33c4a7
commit d656ba7eba

View file

@ -5,7 +5,7 @@ import clonedeep from 'lodash.clonedeep'
import { useSnapshot } from 'valtio' import { useSnapshot } from 'valtio'
import api from '~utils/api' import api from '~utils/api'
import { accountState } from '~utils/accountState' import { accountState, initialAccountState } from '~utils/accountState'
import { appState, initialAppState } from '~utils/appState' import { appState, initialAppState } from '~utils/appState'
import Header from '~components/Header' import Header from '~components/Header'
@ -51,10 +51,15 @@ const TopHeader = () => {
function logout() { function logout() {
removeCookie('user') 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 appState.party.editable = false
// TODO: How can we log out without navigating to root
router.push('/') router.push('/')
return false return false
} }