we can store session storage like that
store token should be like
localStorage.setItem('user', JSON.stringify({ token: token, username: username }));
Store Session in to sessionStorage
You can store both string and array into session storage
String Ex.
let key = 'title';
let value = 'session';
sessionStorage.setItem(key, value);
Array Ex.
let key = 'user';
let value = [{'name':'shail','email':'[email protected]'}];
value = JSON.stringify(value);
sessionStorage.setItem(key, value);
Get stored session from sessionStorage by key
const session = sessionStorage.getItem('key');
Delete saved session from sessionStorage by key
sessionStorage.removeItem('key');
Delete all saved sessions from sessionStorage
sessionStorage.clear();
Store items in to localStorage
You can store both string and array into location storage
String Ex.
let key = 'title';
let value = 'session';
localStorage.setItem(key, value);
Array Ex.
let key = 'user';
let value = [{'name':'shail','email':'[email protected]'}];
value = JSON.stringify(value);
localStorage.setItem(key, value);
Get stored items from localStorage by key
const item = localStorage.getItem('key');
Delete saved session from localStorage by key
localStorage.removeItem('key');
Delete all saved items from localStorage
localStorage.clear();