No More Posting New Topics!

If you have a question or an issue, please start a thread in our Github Discussions Forum.
This forum is closed for new threads/ topics.

Navigation

    Quasar Framework

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search

    Vuex Persisten State duplicate key

    Framework
    2
    2
    111
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • J
      jhon last edited by

      Hi Friends

      I am using vuex-persistenstate to persist data across cokkies with a boot.

      import { Cookies } from 'quasar'
      import createPersistedState from 'vuex-persistedstate'
      
      export default function ({ store, ssrContext }) {
        const cookies = process.env.SERVER
          ? Cookies.parseSSR(ssrContext)
          : Cookies
      
        createPersistedState({
          key: '_mtdc',
          paths: ['auth.token', 'auth.profileUser'],
          storage: {
            getItem (key) {
              return JSON.stringify(cookies.get(key))
            },
            setItem (key, value) {
              console.log(key, value)
              cookies.set(key, value, {
                expires: 30,
                path: '/'
              })
            },
            removeItem (key) {
              cookies.remove(key)
            }
          }
        })(store)
      }
      

      But cookies are repeating in the browser

      Set-Cookie: _mtdc=%7B%22auth%22%3A%7B%22token%…
      67251359-a1f5-4242-aa8e-9ce5ae2cfa2b-imagen.png

      Any suggestions on how I could avoid this behavior
      Thanks

      dobbel 1 Reply Last reply Reply Quote 0
      • dobbel
        dobbel @jhon last edited by

        @jhon

        Maybe quasar’s cookie plugin allows duplicate keys? What if you first check if the cookie key exists before doing cookies.set?

        See here:
        https://quasar.dev/quasar-plugins/cookies#Verify-if-Cookie-is-Set

        1 Reply Last reply Reply Quote 0
        • First post
          Last post