bjoluc/next-redux-cookie-wrapper

Changing compress config to false throws 'SyntaxError: Unexpected token N in JSON at position 0' error

rezasohrabi opened this issue · 1 comments

Hello, First of all thanks a lot for this amazing wrapper.
I need to persist cookie without compression, but when i change compress config to false bellow error happens:

SyntaxError: Unexpected token N in JSON at position 0
at JSON.parse ()
at Function._decodeState (/home/rezasohrabi/Desktop/node_modules/next-redux-cookie-wrapper/dist/next-redux-cookie-wrapper.cjs.development.js:170:17)
at StateCookies.getAll (/home/rezasohrabi/Desktop/node_modules/next-redux-cookie-wrapper/dist/next-redux-cookie-wrapper.cjs.development.js:204:46)
at Object.dispatch (/home/rezasohrabi/Desktop/node_modules/next-redux-cookie-wrapper/dist/next-redux-cookie-wrapper.cjs.development.js:332:40)

I am persisting user object, here is my wrapped store codes:

const makeStore = wrapMakeStore(() =>
  configureStore({
    reducer: rootReducer,
    middleware: (getDefaultMiddleware) =>
      getDefaultMiddleware()
        .prepend(
          nextReduxCookieMiddleware({
            subtrees: [
              {
                cookieName: 'userV3',
                subtree: 'auth.user',
                compress: false,
              },
            ],
          })
        )
        .concat(logger as ReturnType<typeof getDefaultMiddleware>),
  })
)

Hi @rezasohrabi, thanks for the kind words! I'm assuming that you didn't delete the old (compressed) cookies after setting compress to false and now JSON.parse is trying to parse the compressed JSON string? Please re-open if that's not the case. Thanks!