i have stored an id as a key and a token as a value e.g id=token in the localStorage. How can i reference the id so that i can delete the token and log out the user. When two users login and one logs out, he makes the another user log out to.
Like When one user logs in, he overwrites the id=token in the localStorage. This happens when users are using the same browser
userContext.js file
const UserContext = ({ children }) => {
const [me, setMe] = useState(JSON.parse(localStorage.getItem("user")));
let id = localStorage.getItem('id_token');
const [user, dispatch] = useReducer(reducer, {
id,
isAuthenticated: !!localStorage.getItem(id),
});
return (
<UserState.Provider value={{ user, dispatch, id, me }}>
{children}
</UserState.Provider>
);
};
signOut.js file
function signOut(dispatch, id) {
localStorage.removeItem(id);
dispatch({ type: "SIGN_OUT", id });
localStorage.removeItem("user");
localStorage.removeItem("id_token");
return;
}