This repository has been archived by the owner on Feb 4, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 379
argument str must be a string on nuxt server persist #398
Comments
i have this issue as well in new version, currently i use vuex-persistedstate 3.1.0 and it works perfectly. |
I fixed this issue by checking is let headerCookie = req.headers.cookie;
if (typeof headerCookie !== 'string') {
headerCookie = '';
}
const parsedCookies = cookie.parse(headerCookie);
return parsedCookies[key]; |
This seem to be more like a Nuxt issue on how it handles incoming cookies. |
I this it's problem of |
@ilyapisany I still seem to get the I have added to Nuxt like so:
And plugins:
Any ideas? |
same here.. has anyone can fixed it? |
a one liner alternative that worked for me was const parsedCookies = cookie.parse(req.headers.cookie ?? "");
return parsedCookies[key]; or the full the plugin // plugins/persistedState.js
import createPersistedState from "vuex-persistedstate";
import Cookies from "js-cookie";
import cookie from "cookie";
export default ({ store, req }) => {
createPersistedState({
paths: [...],
storage: {
getItem: key => {
if (process.server) {
const parsedCookies = cookie.parse(req.headers.cookie ?? "");
return parsedCookies[key];
} else {
return Cookies.get(key);
}
},
setItem: (key, value) => Cookies.set(key, value, { expires: 1, secure: false }),
removeItem: key => Cookies.remove(key)
}
})(store);
}; |
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
vuex-persistedstate
version: ^4.0.0-beta.3node
version: v10.19.0npm
(oryarn
) version: npm v16.14.4What you did: Install package and use default plugin from readme (nuxt cookie server persist)
What happened: If no cookie set (example on first page loading).
throws type error
argument str must be a string
Reproduction sandbox:
Problem description: cookie package receive string as first parameter but undefined given on empty cookie in browser
Suggested solution: Check is request.headers.cookie is string and set it to blank if not
The text was updated successfully, but these errors were encountered: