abersager / redux-persist-cookie-storage

Redux Persist storage adapter for cookies
MIT License
92 stars 10 forks source link

keyPrefix isn't handled right #4

Closed modosc closed 6 years ago

modosc commented 7 years ago

i was in the middle of another pr when i found this - i'm not sure the best way forward.

it looks like there are two places to set keyPrefix, in the new CookieStorage() instantiation or as part of the options passed to createPersistor from redux-persist.

if i set keyPrefix in createPersistor then i can't get the custom expiration logic here to work correctly.

consider a reducer foo - if keyPrefix='_' in createPersistor then the CookieStorage's (get|set|remove)Item methods will all be called with _foo as the key instead of foo.

if i set keyPrefix in the CookieStorage (and not in createPersistor) things still don't work correctly because redux-persit will set a default prefix of reduxPersist: which still breaks this logic.

abersager commented 7 years ago

Hi, sorry for the late reply.

CookieStorage doesn't know about the prefix used by redux-persist. As you say, (get|set|remove)Item) methods get called with the prefix.

Therefore, if you'd like to use custom expiration for individual keys, you need to include the redux-persist provided prefix in the configuration. For instance, using default reduxPersist: prefix:

new CookieStorage({
  expiration: {
    default: null,
    "reduxPersist:foo": 600
  }
})

Could you try and see if this works for you? If so, I will update the example in the README to explain this properly.

abersager commented 6 years ago

Please reopen if this is still an issue for you.