kamranahmedse / redux-persist-expire

Expiring transformer for redux-persist
MIT License
78 stars 12 forks source link

it's did't work #7

Closed zhangwei900808 closed 5 years ago

zhangwei900808 commented 5 years ago

I used redux-persist-expire,but when I refresh the localstorage it did not work ,which is wrong!

const persistConfig = {
  transforms: [
    // encryptor,
    expireReducer("authReducer", {
      expireSeconds: 10
    })
  ],
  key: config.persist,
  storage,
  version: 2,
  migrate: createMigrate(migrations, { debug: false })
};

const finalReducer = persistReducer(persistConfig, createRootReducer(history));

image

kamranahmedse commented 5 years ago

You need to pass autoExpire: true as an option to the expireReducer. Try changing the expireReducer options to be like below

      expireReducer('authReducer', {
        expireSeconds: 10,
        autoExpire: true
      })
zhangwei900808 commented 5 years ago

@kamranahmedse thanks your resolve my problem :) but when I used encryptor that localstorage data is error and while you refresh the brower is always lost authReducer ,you can see below code

import createEncryptor from "redux-persist-transform-encrypt";
import expireReducer from "redux-persist-expire";

const encryptor = createEncryptor({
  secretKey: "hiynn",
  onError: function(error) {}
});

const expireTransform = expireReducer("authReducer", {
  expireSeconds: 10,
  expiredState: {},
  autoExpire: true
});

const persistConfig = {
  transforms: [
    encryptor,
    expireTransform
  ],
  key: config.persist,
  storage,
  version: 2,
  migrate: createMigrate(migrations, { debug: false })
};

image