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

reduxCookiesMiddleware serializes the string input state, which adds the unnecessary quotes to cookie value #59

Open
ghost opened this issue Feb 12, 2021 · 0 comments

Comments

@ghost
Copy link

ghost commented Feb 12, 2021

Hello, I had some issues using this middleware, so I'd like to kindly ask you to check this problem.

What I wanted to do is to save the language code (like "en" or "ko") in redux state, and load it from cookie values using your middleware.

Loading the cookie value works just fine, but when I try to change the state, the unnecessary "%22" (which stands for ") characters are added to the cookie value.
As I am using 'i18next-browser-languagedetector' which directly reads the cookie and loads the value, It is hard for me to force-remove the quotes.

I found that the issue comes from the store function in "reduxCookiesMiddleware"

if (deleteCheck(nextVal)) {
    options.setCookie(state.name, JSON.stringify(nextVal), 0);
} else {
    options.setCookie(state.name, JSON.stringify(nextVal));
}

When I added the type check like this:

if (deleteCheck(nextVal)) {
    if (typeof nextVal === "string") {
        options.setCookie(state.name, nextVal, 0);
    } else {
        options.setCookie(state.name, JSON.stringify(nextVal), 0);
    }
} else {
    if (typeof nextVal === "string") {
        options.setCookie(state.name, nextVal);
    } else {
        options.setCookie(state.name, JSON.stringify(nextVal));
    }
}

the issue was solved.
Therefore I'd like to ask you if you can add the type checking logic like this.

If there is anything unclear, please let me know. Thank you.

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

0 participants