"isAuthenticated" React Hook not working properly

Hello there, Im console-loggin my isAuthenticated hook in React and its not working properly. Printing true to the console when im not connected, printing false after authentication, sometimes printing the correct result. I am sure its not working properly since I check on Metamask if im connected.

Started to slow down my production so I decided to ask here. Updated Moralis dependency on React but still not working.

Thanks

isAuthenticated is related to MetaMask? Isn’t related to current user being authenticated or not?

I mean, Im thinking its related to wallets in general to connect to Web3? Cant think of an authentication other than Web3 and my wallet showing me when its connected to the site (And the console printing different results when authenticating and unauthenticating with metamask)

Is authenticated is not same thing as MetaMask being connected, you have a different hook to check if web3 is connected.

The difference is between authentication and having access to the web3 account

  • authenticated (isAuthenticated) means being authenticated to your moralis server (this can be via a metamask signature)
  • having access to web3 (isWeb3Enabled) means that you have access to the web3 address and can use web3 functionalities

Being authenticated and being connected to metamask might differ, (but they might be the same)

  • When you call authenticate(), your app will authenticate by using metamask. So then isAuthenticated and isWeb3Enabled will both be true
  • You might call enableWeb3(), without authenticating(authentication on the Moralis server), then isWeb3Enabled is true, and isAuthenticated is false. You will not have userdata from moralis, but you will have access to the web3 account and can use web3 functionalities
2 Likes

thanks for the reply, just tried isWeb3Enabled and enableWeb3 using the react-moralis documentation but still getting console.log(isWeb3Enabled) printing false when my Metamask is connected (using enableWeb3)

@cryptokid @Erno

Does it work with the example code? Found on: https://github.com/MoralisWeb3/react-moralis#enable-web3-via-metamask ?

Otherwise please share code on how to reproduce this issue.

Yeah I used that code. Here I show examples:

Then I call the onClick function with <Button onClick={() => onClick()} id="start-connect"><p>CONNECT WALLET</p></Button>

Here are the results (attention to the console.log)

ps the EnableWeb3 function there i got it from the react-moralis docs but as you can see im not using it. Even in the docs they straight up use the enableWeb3 hook

Ah I see. You need to click the “not connected” button in metamask.
In metamask “connected”/“not connected” means if you have given permission to use that address on a website.

Because this account is not “connected”, your app (and thus moralis functions) has no access to this account. My assumption is that you are still getting isWeb3Enabled===true because another account in Metamask actually is connected. So that one will be used.

No other Metamask accounts connected, in fact this is a new wallet I made just for development. Im losing my mind

Can you click on “not connected” in metamask, and connect the account?

I disconnect my wallet directly from Metamask (so it says “not connected”) and then I retry connecting with hooks. Output in the console still not working properly

maybe you can listen to an event for that disconnect if you want to cover this case when someone disconnects from MetaMask

not sure if im understanding you correctly but there are no events that provide that funcionality