samie820/hooks-state-management

Error in stringifying token

Opened this issue · 1 comments

Hey,
I was trying out the tutorial and didn't have a problem with saving the user/token to localStorage, but I did have trouble pulling the token back. It took me about 3 days to find out it was because the token itself was being stringified, which my backend couldn't interpret.

On the tutorial app.js shows (lines 17-19):

case "LOGIN": localStorage.setItem("user", JSON.stringify(action.payload.user)); localStorage.setItem("token", JSON.stringify(action.payload.token));

Mine worked by doing:

case "LOGIN": localStorage.setItem("token", action.payload.jwt);

I understand saving the user to localStorage is optional, and that worked ok. But stringifying the token caused all sorts of problems.

@dekadekadeka my apologies for the late reply, I've been AWOL. Thanks for the feedback. From your suggestion should I change the code?