Seb-L / pinia-plugin-persist

Persist pinia state data in sessionStorage or other storages.
https://Seb-L.github.io/pinia-plugin-persist/
MIT License
215 stars 37 forks source link

Storage not found when using in nuxt environment #37

Open mishka86 opened 2 years ago

mishka86 commented 2 years ago

There is no problem when using the Basic Usage method. When using separate storage(localStorage, sessionStorage) for strategies in Advanced Usage I get an 'is not defined' error. Do I need any special settings?

LokiWasHere commented 2 years ago

I encountered the same problem, to solve it while waiting for a patch, it is possible to add a condition on the storage process.client. That way, it will be ignored on the server-side.

Example of code:

// store/index.ts
export const useState = defineStore('keyValue', {
  // states & actions & getters
  // 
  // 
  // 
  persist: {
    enabled: true,
    strategies: [
      { key: "keyValue", storage: process.client ? sessionStorage : null },
    ]
  }

})