Global auto persist config option in nuxt.conf.ts
kosaka18 opened this issue · 1 comments
kosaka18 commented
Clear and concise description of the problem
While the base plugin itself supports auto persist option, the corresponding Nuxt module lacks support for setting it in nuxt.conf.ts.
export default defineNuxtConfig({
piniaPersistedstate: {
storage: 'localStorage',
auto, // <= this setting is currently missing.
},
})
Suggested solution
In the module.ts:
export interface ModuleOptions {
storage: 'cookies' | 'localStorage' | 'sessionStorage'
debug: boolean
cookieOptions: CookieOptions
auto: boolean // <= Add this
}
export default defineNuxtModule<ModuleOptions>({
meta: {
name: '@pinia-plugin-persistedstate/nuxt',
configKey: 'piniaPersistedstate',
compatibility: {
nuxt: '^3.0.0',
bridge: false,
},
},
defaults: {
storage: 'cookies',
debug: false,
cookieOptions: { },
auto: false, // <= Add this
},
In the plugin.ts:
export default defineNuxtPlugin((nuxtApp) => {
const {
cookieOptions,
debug,
storage,
auto // <= Add this
} = useRuntimeConfig().public.persistedState as ModuleOptions
const pinia = nuxtApp.$pinia as Pinia
pinia.use(createPersistedState({
storage: storage === 'cookies'
? persistedState.cookiesWithOptions(cookieOptions)
: persistedState[storage],
debug,
auto, // <= Add this
}))
})
Alternative
No response
Additional context
No response
Validations
- Follow our Code of Conduct
- Read the Contributing Guide.
- Check that there isn't already an issue that request the same feature to avoid creating a duplicate.