I'm trying to remove all user data from the persisted state, when a user logs out. For managing my state I'm using Zustand and followed this guide: https://docs.pmnd.rs/zustand/guides/typescript
I'm creating my store as follows:
export const useStore = create<Slices>()(
persist(
devtools((...x) => ({
...createProfileSlice(...x),
...createSessionSlice(...x),
...createStatusSlice(...x),
})),
{
name: CONFIGURATION.STATE.NAME,
partialize: (state) => Object.fromEntries(Object.entries(state).filter(([key]) => !['session', 'isLoading'].includes(key))),
}
)
);
My question is now, how to remove all data from the persisted store, when a user logs out. I've tried to clear the localstorge with localstorage.clear()
, but Zustand sets the whole state when the next change at the state is done again.
I've also found the following guide: https://docs.pmnd.rs/zustand/guides/how-to-reset-state This guide uses another structure and honestly I don't understand what is going on. How can I delete all user data from the persisted state when a user logs out?