robinvdvleuten / vuex-persistedstate

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

secure-ls | Uncaught Error: Could not parse JSON #429

Closed NorseGaud closed 3 years ago

NorseGaud commented 3 years ago
import { createStore } from 'vuex'
. . .
import createPersistedState from "vuex-persistedstate";
import SecureLS from "secure-ls";
const ls = new SecureLS({ isCompression: false });

export default new createStore({
  state: {
    count: 0
  },
  plugins: [
    createPersistedState({
      storage: {
        getItem: (key) => {
          console.log(key)
          ls.get(key)
        },
        setItem: (key, value) => ls.set(key, value),
        removeItem: key => ls.remove(key)
      }
    })
  ],
  modules: {
    xxxx,
    search
  }
});

Loading the page shows

index.js:163 Uncaught Error: Could not parse JSON
    at SecureLS2.get (index.js:163)
    at Object.getItem (index.js?t=1631830051988:19)
    at n2 (index.ts:38)
    at s (index.ts:80)
    at index.ts:90
    at vuex.esm-bundler.js:935
    at Array.forEach (<anonymous>)
    at new Store2 (vuex.esm-bundler.js:935)
    at new createStore (vuex.esm-bundler.js:880)
    at index.js?t=1631830051988:10

And the console.log(key) shows a string of "vuex".

NorseGaud commented 3 years ago

This seems like a secure-ls problem, but I'm not knowledgeable enough to be sure. Can someone confirm?

NorseGaud commented 3 years ago

Found it: https://github.com/softvar/secure-ls/issues/9

just had to clear my cache :angry: