This repository was archived by the owner on Aug 31, 2025. It is now read-only.
File tree Expand file tree Collapse file tree 3 files changed +13
-10
lines changed
Expand file tree Collapse file tree 3 files changed +13
-10
lines changed Original file line number Diff line number Diff line change @@ -90,6 +90,7 @@ export const useStore = defineStore('main', {
9090> The ` persistedState.cookies ` method accept an object parameter to configure cookies with the following options (inherited from Nuxt's ` useCookie ` ):
9191>
9292> - [ ` domain ` ] ( https://nuxt.com/docs/api/composables/use-cookie#domain )
93+ > - [ ` encode ` ] ( https://nuxt.com/docs/api/composables/use-cookie#encode ) /[ ` decode ` ] ( https://nuxt.com/docs/api/composables/use-cookie#decode )
9394> - [ ` expires ` ] ( https://nuxt.com/docs/api/composables/use-cookie#maxage-expires )
9495> - [ ` httpOnly ` ] ( https://nuxt.com/docs/api/composables/use-cookie#httponly )
9596> - [ ` maxAge ` ] ( https://nuxt.com/docs/api/composables/use-cookie#maxage-expires )
@@ -143,7 +144,7 @@ export const useStore = defineStore('main', {
143144
144145The module accepts some options defined in ` nuxt.config.ts ` under the ` piniaPluginPersistedstate ` key:
145146
146- - [ ` cookieOptions ` ] ( #cookies )
147+ - [ ` cookieOptions ` ] ( #cookies ) (except ` decode ` and ` encode ` as functions are not supported)
147148- ` debug `
148149- [ ` key ` ] ( #global-key )
149150- ` storage `
Original file line number Diff line number Diff line change 1- import type { CookieOptions } from 'nuxt/app '
1+ import type { CookiesStorageOptions } from './runtime/storages '
22import type { PersistenceOptions } from './types'
33import {
44 addImports ,
@@ -15,19 +15,18 @@ type ModuleOptions = Pick<PersistenceOptions, 'debug'> & {
1515 * Default storage for persistence. Only accepts presets.
1616 */
1717 storage ?: 'cookies' | 'localStorage' | 'sessionStorage'
18+
1819 /**
1920 * Global key template, allow pre/postfixing store keys.
2021 * @example 'my-%id-persistence' will yield 'my-<store-id>-persistence'
2122 */
2223 key ?: `${string } %id${string } `
24+
2325 /**
2426 * Options used globally by default cookie storage.
2527 * Ignored for other storages.
2628 */
27- cookieOptions ?: Omit <
28- CookieOptions ,
29- 'encode' | 'decode' | 'default' | 'watch' | 'readonly' | 'filter'
30- >
29+ cookieOptions ?: Omit < CookiesStorageOptions , 'encode' | 'decode' >
3130
3231 /**
3332 * Automatically persist all stores with global defaults, opt-out individually.
Original file line number Diff line number Diff line change 1- import type { PublicRuntimeConfig } from '@nuxt/schema '
1+ import type { CookieOptions } from '#app '
22import type { StorageLike } from '../types'
33import { useCookie , useRuntimeConfig } from '#app'
44
5- type CookiesStorageOptions = PublicRuntimeConfig [ 'piniaPluginPersistedstate' ] [ 'cookieOptions' ]
5+ export type CookiesStorageOptions = Omit <
6+ CookieOptions ,
7+ 'default' | 'watch' | 'readonly' | 'filter'
8+ >
69
710/**
811 * Cookie-based storage. Cookie options can be passed as parameter.
@@ -14,15 +17,15 @@ function cookies(options?: CookiesStorageOptions): StorageLike {
1417 key ,
1518 {
1619 ...( options ?? useRuntimeConfig ( ) . public . piniaPluginPersistedstate . cookieOptions ?? { } ) ,
17- decode : decodeURIComponent ,
20+ decode : options ?. decode ?? decodeURIComponent ,
1821 readonly : true ,
1922 } ,
2023 ) . value ,
2124 setItem : ( key , value ) => useCookie < string > (
2225 key ,
2326 {
2427 ...( options ?? useRuntimeConfig ( ) . public . piniaPluginPersistedstate . cookieOptions ?? { } ) ,
25- encode : encodeURIComponent ,
28+ encode : options ?. encode ?? encodeURIComponent ,
2629 } ,
2730 ) . value = value ,
2831 }
You can’t perform that action at this time.
0 commit comments