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

"token" in local storage holds string "[object Object]" #1894

Open
renatoka opened this issue Mar 9, 2025 · 1 comment
Open

"token" in local storage holds string "[object Object]" #1894

renatoka opened this issue Mar 9, 2025 · 1 comment

Comments

@renatoka
Copy link

renatoka commented Mar 9, 2025

Describe the bug
Upon register we are setting returned authToken into local storage. As returned value is an object but we are not stringifying it, it's being shown as [object Object] in local storage, which is wrong. This means that we won't be able to access any value from it as it's not really an object, but rather a string. Upon trying to parse it, client will "crash" because JSON.parse(localstorage.getItem("token")) can't pase string "[object Object]".

To verify this, run the following code console.log(typeof (localStorage.getItem("token")),localStorage.getItem("token"));. It's output is string [object Object].

To Reproduce
Steps to reproduce the behavior:

  1. Go to 'Register' page as fresh user, or log out from current user and attempt to register again.
  2. Fill out all information and submit your request.
  3. After successful registration, check your local storage in browser for saved "token" value.
  4. Notice that it's a string with value [object Object]

Expected behavior
"token" value should be correctly saved as stringified object and not actual string so it can be later accessed by using JSON.parse() function.

Screenshots

Current code:
Image

Image

Proposed change in upcoming PR:
Image

Image
@renatoka
Copy link
Author

renatoka commented Mar 9, 2025

Please assign.

@renatoka renatoka changed the title "token" in local storage holds string "[object Object"] "token" in local storage holds string "[object Object]" Mar 9, 2025
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

1 participant