Using createPersistedState in a vuex and quasar application: A complete guide

Looking for help with using createPersistedState in a vuex and quasar setup.

I've been attempting to save some data in the cookie of my application, but it doesn't seem to be working as expected. Any ideas on what could be going wrong?

Appreciate any insights you can provide. Thank you!

Action

function setUser ({ commit }) {
  axios.get(`/modulo/app`, { headers: { 'Authorization': 'Bearer ' + store.getters.getToken() } })
    .then(response => {
      commit('setUserMutation', response.data)
    })
    .catch(error => {
      if (!error.response) {
        console.log(error.response)
      }
    })
}

Mutation

const setUserMutation = (state, data) => { state.user = data }

Getters

function getUser (state) {
  return state.user
}

index config Store

export default function () {
  const Store = new Vuex.Store({
    modules: {
      auth
    },
    plugins: [createPersistedState(
      {
        paths: ['auth.setUserMutation'],
        storage: {
          getItem: key => Cookies.get(key),
          setItem: (key, value) => Cookies.set(key, value, { expires: 3, secure: true }),
          removeItem: key => Cookies.remove(key)
        }
      }
    )],
    strict: process.env.DEV
  })
  return Store
}

Answer №1

It is highly probable that the issue is related to the secure properties being used in Cookie.set

Secure

This can be set as true or false, indicating whether the cookie transmission requires a secure protocol (https).

-https://github.com/js-cookie/js-cookie

If you are working on localhost, it is unlikely using HTTPS.

You have the option to adjust the secure value according to your environment by utilizing an environment variable

secure: process.env.NODE_ENV === 'production'

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Achieving reactivity in Vue when pushing elements into a dynamically-sized array

I am in need of a two-dimensional array that can have dynamic keys and an array of objects pushed to it. I have tried using this.$set and Vue.set without any success so far. data() { rep_recs: [] , // I want this array to be reactive so that I can displ ...

Troubleshooting: Issue with v-link to classname in Vue.js

This is the code I am working with: <div v-link="'/work/' + {{data.useClass}}" class="itemImg {{data.useClass}}"> When rendered in the browser, it looks like this: <div class="itemImg x50"> The expectation is that class="itemImg { ...

Using Vue's interpolation within the src attribute of my image tag: "{{ image }}"

I am attempting to pass an image url dynamically to my Vue application, but it doesn't seem to be working. I'm starting to question if this is even achievable in Vue / Vuetify. Please confirm if this functionality is possible. <v-img class=& ...

Exploring SVG Morphing Reversal Techniques in Anime.js

I have been trying to implement direction: 'reverse' and timeline.reverse(), but so far it hasn't been successful. Interestingly, when I set loop: true, the reverse animation can be seen within the loop. However, my goal is to trigger this a ...

Challenges with setting up Vue.js

I've been attempting to install vue.js but have had no success, even though my npm is up to date. When I try running vue init webpack vueapp, I encounter the following error: No command 'vue' found, did you mean:Command 'vpe' fr ...

Vuex getters consistently seem to yield null values

Whenever I utilize a Vuex getter in my Vue.js component, it keeps returning null for me. Below is the code snippet: MainLayout.vue <script> import NavBar from '@/components/NavBar.vue' import ToolBar from "@/components/ToolBar" ...

Vuetify vueJS dialog with elevated design

Is there a way to completely remove the elevation of a v-dialog so that it has no shadow at all? The elevation property in the v-dialog itself and using the class as Class = "elevation-0" have not worked for me. Here is the link to the component ...

sort response data based on date in vue

Is there a way to sort response data by date in vue2? Specifically, how can we filter the data by month, year, or week when a corresponding button is clicked? Here's an example of the response data I received: [ { "date": "2017-02-05", "views": 1, "r ...

How can I assign several Objects to a single array?

My goal is to save several objects into an array. Specifically, I have five objects named obj1, obj2, obj3, obj4, and obj5. ...

Executing asynchronous callback with Electron and Vue using nodeffi

Currently, I am experimenting with using Async along with a received Buffer. While I am able to obtain the correct answer, I am facing challenges in accessing variables outside of the callback function. Specifically, I am attempting to assign the value o ...

What is the process for converting a string literal into raw JSON and then storing it?

When trying to edit object values using a text input element and JSON.stringify(txt, null, 2), everything seems fine initially. However, after submitting the input, I end up with unwanted characters like "/n" and "\" within the string literal. Despite ...

Changing Vuex store state by using mapped actions within the render function of a Vue component

I have been working on a slider with a modal that should open when an image is clicked. The modal state is stored in my Vuex store, and I need to dispatch an action from the image tag within my render function. While following Vue documentation, I have at ...

Vue - Struggling to invoke sweetalert2 within a method

I'm encountering an issue with launching sweetalert within a Vue method. When I directly call the sweetalert in the script, it works fine. However, when I try to launch the sweetalert upon clicking a button, nothing happens (no errors in the console). ...

The Vue.js v-on:mouseover function is not functioning properly in displaying the menu

When I hover over a LI tag, I want to display a menu. I have successfully implemented it using a simple variable with the following code: @mouseover="hoverFormsControls=true" @mouseleave="hoverFormsControls=false" However, when I attempted to use an arr ...

Elevate the element from the choice API to the organization API using this.$parent

I recently developed a Vue 3 component called "Tab" using the option API. Here is the code: export default { name: "Tab", props: { name: {required: true}, iconClass: {required: true}, selected: {default: false} }, da ...

Solving the CORS problem between Vue.js and Flask: Troubleshooting XMLHttpRequest Blockade

Description: Currently working on developing a web application utilizing Vue.js for the frontend and Flask for the backend. The initial phase involves creating a simple login page, but encountering CORS (Cross-Origin Resource Sharing) issues when making r ...

Issue with Local Storage: Value not being saved, instead [object MouseEvent] being stored

I am truly grateful for the help from @zim as it allowed me to drastically simplify my code for 2 buttons that store true/false values locally. However, I am facing an issue where the button click is registering as [object MouseEvent] instead of True/False ...

Tips for including vue-autonumeric in your webpack 2 setup

Encountering a problem while bundling the vue-autonumeric package with Webpack 2, where the dependency AutoNumeric is not being found properly. Although there is an alias set up in the configuration that works fine with webpack 3, it seems to fail when wo ...

Is there a way to load information retrieved from an API into a dropdown menu in Laravel with the help of VueJS and axios?

After many attempts, I still can't seem to fetch my API data into a select list successfully. Everything seems to be retrieved properly, but when it comes to displaying them, nothing shows up. Could there be an issue with my code? Here's my rout ...

Connecting radio buttons to data in Vue using render/createElement

How do you connect the value of a selected radio button to a specific variable in the data object within a Vue application when using the render/createElement function? ...