robinvdvleuten / vuex-persistedstate

💾 Persist and rehydrate your Vuex state between page reloads.
https://npm.im/vuex-persistedstate
MIT License
5.76k stars 378 forks source link

Nuxt universal not working. Cookies storage doesn't work at all #385

Closed bsor-dev closed 3 years ago

bsor-dev commented 3 years ago

Same thing here #151 and here #44 I already did everything there. Even their sanbox example doesn't work either https://codesandbox.io/s/xl356qvvkz I already tried this in all browser. And weird part is, there's a time that it working. It saves on cookies but doesn't rehydrate when u refresh the page. And sometimes it doesn't save the cookies. What is the trick here to make it work

import createPersistedState from 'vuex-persistedstate'
import * as Cookies from 'js-cookie'
import cookie from 'cookie'

export default ({ store, isDev, isHMR, req }) => {

  createPersistedState({
    key: 'ot',
    paths: ['user', 'posts', 'up'],
    storage: {
      getItem: (key) =>
        process.client
          ? Cookies.getJSON(key)
          : cookie.parse(req.headers.cookie || '')[key],
      setItem: (key, value) =>
        Cookies.set(key, value, { expires: 365, secure: false }),
      removeItem: (key) => Cookies.remove(key),
    },
  })(store)
}
bsor-dev commented 3 years ago

Finally it works now. All I need is cookie-universal-nuxt and I follow this . Probably the reason is I got a large data size that's why it doesn't save.