Skip to content
This repository has been archived by the owner on Feb 4, 2022. It is now read-only.

One cookie by module with JS-COOKIE #432

Open
RaphaelMcledger opened this issue Oct 4, 2021 · 0 comments
Open

One cookie by module with JS-COOKIE #432

RaphaelMcledger opened this issue Oct 4, 2021 · 0 comments

Comments

@RaphaelMcledger
Copy link

RaphaelMcledger commented Oct 4, 2021

Relevant code or config

import Vue from "vue";
import Vuex from "vuex";
import createPersistedState from "vuex-persistedstate";
import Cookies from "js-cookie";
import module1 from "./module1";
import module2 from "./module2";

Vue.use(Vuex);
let secure = true;

const storage = (e) => {
  return {
    getItem: () => {
      Cookies.get(e);
      console.log(Cookies.get(e));
    },
    setItem: (key, value) => {
      Cookies.set(e, JSON.stringify(JSON.parse(value)[e]), { expires: 3, secure: secure });
    },
    removeItem: () => Cookies.remove(e)
  };
};
const modules = {
  module1,
  module2
};
const plugins = [];
Object.keys(modules).forEach((e) => {
  plugins.push(
    createPersistedState({
      key: e,
      storage: storage(e)
    })
  );
});
export default new Vuex.Store({
  state: {},
  mutations: {},
  actions: {},
  plugins: plugins,
  modules: modules
});

What you did:
I want to get one cookie by modules
What happened:
On refresh cookies dispear

Reproduction sandbox:
https://codesandbox.io/s/lively-forest-5pcry

Problem description:
When i console.log Cookies.get() on get in storage i got undefined when
Suggested solution:

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant