Remove Web3UiKit <ConnectButton /> auto-opening Metamask

Hello Moralis, I’m trying using the Moralis Web3UiKit, especially the component, i’m facing an issue when the wallet is not connected, and the page refresh, basically the component automatically call the Metamask pop-up to sign the transaction to authenticate.
This could be really dangerous for user that don’t trust the Dapp…

How can i avoid the button to do that?

ps. i think this happen when the component refresh.

Thank you

Hope you don’t have enableWeb3 called somewhere in your project ?
You can try test your project on another PORT to be very sure it’s causing the problem

Not at the start, it is enabled after the isAuthenticated is true.

Should I enable it before?

Don’t get you really. Having it anywhere in the code might be the cause isAuthenticated no matter the condition because the condition might be valid. You can remove any instance from your code to be sure if the popup is actually caused by the <ConnectButton/>

this is the only part of code where the enableweb3 is written:

const checkAddress = async () => {
    if (isAuthenticated) {
      const web3Provider = await Moralis.enableWeb3();
      const currentAddress = await user.attributes.ethAddress;
      setAddress(currentAddress);
      getNftBalance(address);
      getUnstakedNft(currentAddress);
      getStakedNft(currentAddress);
    }
    return;
  };

  useEffect(() => {
    checkAddress();
  }, [isAuthenticated]);

but also like that is giving the metamask login loop

ps. I confirm again that without the <ConnectButton /> component the login loop is not showing up

pps. By adding ‘moralisAuth={false}’ seems not giving the login loop, but i need it to be true

enableWeb3() won’t trigger the Moralis signature request, only authenticate() does that.

The ConnectButton component shouldn’t be doing that though, can you post your component code (that uses ConnectButton). Are you using the latest web3uikit?

Hey Pietro,
I’m assuming you’re coming from Patricks FCC tutorial.

The reason this is happening is because your browser has injected some text in the local storage which is now interfering with the Web3UI ConnectButton. So you need to clear cookies and all other stored website data.

Try again and should work!

1 Like

Thank you this works