Closed IlirBajrami closed 3 years ago
i fixed this by adding JSON.stringify
to user data
like this:
const submitHandler = async (e) => {
e.preventDefault();
try {
const { data } = await axios.post("/api/users/login", {
email,
password,
});
dispatch({ type: "USER_LOGIN", payload: data });
Cookies.set("userInfo", JSON.stringify(data)); // <------- JSON.stringify added here
router.push(redirect || "/");
} catch (err) {
alert(err.response.data ? err.response.data.message : err.message);
}
};
Is this the right way?
Yes @IlirBajrami, This is the right solution 👍
Ok, thanks!
The same issue is in pages/register.js.
JSON.stringify()
should be added to user data
in Cookies.set()
.
I'm having the
SyntaxError: Unexpected token o in JSON at position 1
when saving theuserInfo
to Cookie. The Cookie value is[object%Object]
What am i doing wrong?