I'm persisting a logged in session with React and localStorage
functionality:
axios
.post(url, data, headers)
.then(resp => {
if (resp.data.message === "successfully logged in") {
setAuthenticated(true);
setUserID(resp.data.id);
setSessionUsername(resp.data.username);
setSessionEmail(resp.data.email);
setDisplayGreeting(true);
localStorage.setItem("user", resp.data);
console.log(resp.data);
when I'm trying to retrieve the JSON object back:
useEffect(() => {
const loggedInUser = localStorage.getItem("user");
if (loggedInUser) {
console.log(loggedInUser);
The output in the console says "Object [object]". What am I doing wrong ?