Skip to content

Commit

Permalink
docs: update nuxt-integration plugin example
Browse files Browse the repository at this point in the history
  • Loading branch information
stephenjason89 committed Jan 16, 2025
1 parent 7113a6b commit 9617760
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 3 deletions.
1 change: 0 additions & 1 deletion docs/api/persist-options.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ import { defineStore } from 'pinia'
export const useStore = defineStore('exampleStore', {
persist: {
key: 'exampleStore', // Defaults to the store's ID
debug: false, // Debugging disabled
overwrite: false, // Do not overwrite existing state
filter: () => true, // Always allow persistence
clientOnly: false, // Run on both server and client
Expand Down
5 changes: 3 additions & 2 deletions docs/guide/nuxt-integration.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,19 @@ To persist state using cookies in a Nuxt application, we recommend using [`cooki
```ts twoslash
// @filename: pinia-persistence.ts
// @noErrors
import type { Pinia } from 'pinia'
import cookies from 'cookie-universal'
import { createStatePersistence } from 'pinia-plugin-state-persistence'

export default defineNuxtPlugin((nuxtApp) => {
const event = nuxtApp.ssrContext?.event // Access server-side request/response
const Cookies = cookies(event?.node.req, event?.node.res) // Initialize cookie-universal with SSR context

nuxtApp.$pinia.use(
;(nuxtApp.$pinia as Pinia).use(
createStatePersistence({
storage: {
getItem: Cookies.get, // Get item from cookies
setItem: (key, value) => Cookies.set(key, value), // Set item in cookies
setItem: Cookies.set, // Set item in cookies
removeItem: Cookies.remove, // Remove item from cookies
},
}),
Expand Down

0 comments on commit 9617760

Please sign in to comment.