barisates/react-session-api

Can't access keys after refresh when using local storage

Opened this issue · 0 comments

When using local storage, if I set keys and refresh the keys show with the right data in the Session but aren't accessible with Session.get('key');
At the start of app, I set config and print the session object like so:

function App() {
useEffect(() => { Session.config(true, 60); }, []);

console.log(Session);
console.log(Session.items());
console.log(Session.get('username'));
console.log(Session.get('id'));
console.log(Session.get('username'));
console.log(Session.get('email'));`
...
}

But here is the result:
Screen Shot 2022-04-12 at 8 02 09 PM

In my Login.js when I set the keys and console.log them, they show up just fine.
if (res.data) {
Session.set("id", res.data.id);
Session.set("username", res.data.username);
Session.set("email", res.data.email);
Session.set("accessToken", res.data.accessToken);
console.log(Session);
console.log(Session.get('id'));
console.log(Session.get('username'));
console.log(Session.get('email'));
}

Screen Shot 2022-04-12 at 8 04 08 PM

Any idea what I'm doing wrong?