Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

153
Views
Redux-persist keep storing old data even after logout

I am using Redux-persist and Redux toolkit to store data in localstorage. Now, when I logout, I am clearing the complete localStorage, but some data are not getting cleared. When I login with completely different user, I am able to see the previous logged in user data for few seconds.

Here is the logout reducer

 logout: state => {
  state.isSignedIn = false;
  state.username = '';
  localStorage.removeItem('persist:root')
  storage.removeItem(SIGNIN_TOKEN);
},

Here is my store.js file.

import { combineReducers } from 'redux'
import { configureStore, getDefaultMiddleware } from '@reduxjs/toolkit'
import appReducer from './appSlice';
import {
  persistStore,
  persistReducer,
  FLUSH,
  REHYDRATE,
  PAUSE,
  PERSIST,
  PURGE,
  REGISTER
} from 'redux-persist'
import storage from 'redux-persist/lib/storage'

const persistConfig = {
  key: 'DSHP_ROOT',
  version: 1,
  storage
}

const persistedReducer = persistReducer(persistConfig, combineReducers({
  app: appReducer,
}))

export const store = configureStore({
  reducer: persistedReducer,
  middleware: getDefaultMiddleware({
    serializableCheck: {
      ignoredActions: [FLUSH, REHYDRATE, PAUSE, PERSIST, PURGE, REGISTER]
    }
  })
})

export const persistor = persistStore(store)

I tried other solutions suggested in stack overflow which are...

  • Setting state to undefined or {} on logout, it is still not working.
  • Using root reducer to set state to undefine, not working.
  • Tried using persistor.flush() and persistor.purge() not working, can't even login.

The only thing which is working is that, I need to set each and every individual state to its default value which will be difficult since I have so many states and so many reducers (in above code I only added one reducer).

Is there any easy way to clear all state on logout?

Thank you

about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!