React Js Error Unexpected End Of Json When Passing User Token Via Session-storage
I have a login page, which excepts the username and password. Upon button submission, the page processes the user credentials via a json / api and generates a token thus routing th
Solution 1:
You need to stringify the data into sessionStorage
. Otherwise it's going to look like this "[object Object]"
. This is because localStorage
and sessionStorage
can only store DOMStrings and not objects.
The documentation for Storage.setItem
Simple test to verify:
sessionStorage.setItem('token', {'a':1})
let t = sessionStorage.getItem('token')
// "[object Object]".
Post a Comment for "React Js Error Unexpected End Of Json When Passing User Token Via Session-storage"