I have tried some things here.
- Stringify user object and storing to localStorage. Get the user using JSON.parse()
- Storing plain user object. Parsing user when getting.
- etc.
All posibilities either return [Object] object or parse error. What is the correct way?
import { useAuth0, withAuthenticationRequired } from '@auth0/auth0-react';
export const PrivateHome = ({ fetchUserMetaData, user_metadata }) => {
const { user, getAccessTokenWithPopup } = useAuth0();
if (!localStorage.getItem("user")) localStorage.setItem("user", JSON.stringify(user, null, 2))
return (
<h1>Private Home</h1>
)
}
const user = JSON.parse(localStorage.getItem('user'))
errpr
index.js:1 Unexpected token o in JSON at position 1
email: "gmail@gmail.com"
email_verified: true
family_name: "name"
given_name: "name"
locale: "en"
name: "name"
nickname: "nickname"
picture: "picture"
sub: "1231231231764132451235035"
updated_at: "2021-11-21T13:11:43.091Z"
[[Prototype]]: Object