Skip to content

Commit

Permalink
fix: Reset defined store values on user sign-out, #125
Browse files Browse the repository at this point in the history
  • Loading branch information
weaponsforge committed May 7, 2023
1 parent 9df4ce2 commit 7423dc0
Showing 1 changed file with 36 additions and 1 deletion.
37 changes: 36 additions & 1 deletion client/src/lib/hooks/useInitAuth.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { useEffect } from 'react'
import { auth, onAuthStateChanged, signOut } from '@/lib/utils/firebase/config'
import { updateSyncV } from 'use-sync-v'
import { updateSyncV, updateAsyncV } from 'use-sync-v'
import { USER_STATES } from '../store/constants'

/**
Expand Down Expand Up @@ -83,6 +83,41 @@ export default function useInitAuth () {
authStatus: USER_STATES.SIGNED_OUT,
authLoading: false
})

// Reset the contacts store list
updateAsyncV('contacts', () => {
return []
})

// Reset ui and other store states
updateSyncV('show',{
searchField:false,
searchResults:false,
createContactForm:false,
editContactForm:false,
contacts:true,
deleteContactButton:false,
sidebar:false
})

updateSyncV('data',{
activeContact:null,
contacts:null,

})

updateSyncV('ui', {
activeContact: null,
phase: {
createContact: false,
editContact: false,
search: false,
deleteContact: false,
},
search: {
searchKeyword: '',
},
})
}
}

Expand Down

0 comments on commit 7423dc0

Please sign in to comment.