How to carry over Moralis Authenticated state if page refreshes/browser reopens?

Hello all - I have a question regarding wallet connect in regards to Moralis that hopefully, I can get some clarity on.

I find myself in a situation where when authenticating wallet connect to link to my mobile wallet, if I was to refresh the page then a lot of Moralis functionality is broken.

Moralis lets you “authenticate” via your browser with web3 and or by using wallet connect. However, the log-in state doesn’t carry over to refreshes and or if a user closes the browser and opens the webpage again.

Moralis does seem to store some information in local storage - so my question is this - how can one persist the authentication state of the wallet connect and or metamask login via Moralis so that it carries over as it should and so moralis functionality like “sending a transaction” can still work correctly? I am unsure if this is a Moralis-specific issue/bug or if it’s a Moralis/WalletConnect thing.

Thank you for any advice and or solutions you may offer.

I’ve seen 2 other posts with somewhat similar issues but no traction so this is to discuss carrying over the authenticated state over other pages whether it is via metamask, walletconnect, and or magic link.

You can verify the authenticated user details with Moralis.User.current(). This data is cached and will remain even after the refresh.

You can use it as below.

const currentUser = Moralis.User.current();
if (currentUser) {
    // do stuff with the user
} else {
    // show the signup or login page