Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cookie get is not working after chanhing route in asynd fetch or asyncData #122

Open
Venegrad opened this issue Mar 30, 2022 · 4 comments
Open

Comments

@Venegrad
Copy link

Venegrad commented Mar 30, 2022

Im using nuxt $cookies for save some data. When some buttons clicked, im updating cookies:

updateTickets(ctx) {
    this.$cookies.set(`payTickets${ctx.getters.getCurGame}`, ctx.getters.getPayTickets, {
      secure: false
    });
    this.$cookies.set(`tickets${ctx.getters.getCurGame}`, ctx.getters.getTickets, {
      secure: false
    });
  },

Cookie reading action from store:

async cookieWatcher(ctx) {
    let tickets = this.$cookies.get(`tickets${ctx.getters.getCurGame}`);
    let payTickets = this.$cookies.get(`payTickets${ctx.getters.getCurGame}`);

    if(!tickets || !tickets.length) tickets = [[]];
    if(!payTickets || !payTickets.length) payTickets = [];

    ctx.commit("setTickets", tickets);
    ctx.commit("setPayTickets", payTickets);
  },

On page im using:

async fetch({store, $axios, route, $auth, error, params}) {
   store.dispatch("games/cookieWatcher");
}

But thats not working. When i leave page and enter anotherm new cookies is not reading, only after page reload by f5, cookies reading.

for fix that, i need to watch route

created() {
  this.$store.dispatch("games/cookieWatcher");
},
watch: {

    '$route.path'() {
      this.$store.dispatch("games/cookieWatcher");
    }
  },

Guess thats error, cuz cookie need correctly reading from async fetch or asyncData

@Venegrad
Copy link
Author

error in client side route change, need to fix that, any idia?

@microcipcip
Copy link
Owner

I don't understand why it doesn't work. Did you check the browser storage to see if the cookie is actually set when clicking the button?

@stale
Copy link

stale bot commented Aug 13, 2022

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the wontfix This will not be worked on label Aug 13, 2022
@Venegrad
Copy link
Author

I don't understand why it doesn't work. Did you check the browser storage to see if the cookie is actually set when clicking the button?

asyncData is calling every time, when u enter nuxt page. In asyncData im calling store action store.dispatch("games/cookieWatcher"); what reading cookie store this.$cookies.get(tickets${ctx.getters.getCurGame});

@stale stale bot removed the wontfix This will not be worked on label Aug 15, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants