Local storage should be deleted when user disconnects or changes account

If you change the account connected in the metamask. Dapp still recognizes the old user because of some information stored in the local storage.

It seems like the account should be disconnected by default whenever such action happens.

I think that you could add this logic in your code if you want, like logging out the user if the metamask account is changed.
The user that is logged in on Moralis server will keep that session until logout will be made, you can choose to link the new metamask account with current user (if the user wants) too.

1 Like

Actually its not clear how can I do it with moralis.

The usual way without moralis is to register callback functions like this:
ethereum.on("accountsChanged", doSomething);
ethereum.on("chainChanged", doSomething);

But with moralis, it seems I don’t have access to ethereum object?

you may be able to use this syntax directly: Know when MetaMask wallet has switched

1 Like