[SOLVED] Metamask signature request is unapproved: Moralis.link()

I have the following code to get Account change approved by user.

Moralis.onAccountChanged( async (account) => {
const confirmed = confirm("Link this account?");

if (confirmed) {
await Moralis.link(account);
}
});

It works fine, but the issue still remains.
Signature request is not approved. So there is no “Sign” button pops up.

I have to click on the Metamask icon to get “Sign” modal.

This is bad UI for users because they are not prompted to the “Sign” .
Anyone has same issue?

did it work popup open before properly when connecting to any other websites? If yes, then maybe try updating the browser and extension to latest version.

It seems the issue is related to my specific code or Moralis. I have tested the Account change at Uniswap and there it works fine(but no sign popup, it just changes the account behind the scene).

Any suggestion?

The signature request popup not showing may be a local issue on your end. Make sure you’ve closed any existing MetaMask popup windows. You can try in another browser.

Are you saying Moralis.onAccountChanged does not trigger in your app when you switch MetaMask accounts? Which moralis-v1 version are you using?

No. It does trigger the function. I’m saying “Sign” is not prompted when I click on “OK” in the alert.
I have tested on both Brave and Chrome. Same issue for the both.

Would you check the video below? Please note I have closed Metamask after the alert pops up. I could successfully get “Sign” with the method.

Is there a way to get the Sign directly without closing Metamask?

Is there a way to get the Sign directly without closing Metamask?

You may not be able to change that behaviour. It seems ok to me to work like that. Otherwise you could change the interaction e.g. add a “Link” button afterwards instead of using confirm dialog.

It does not change the behavior.

Here is the code:

Moralis.onAccountChanged( async (account) => {

await Moralis.link(account);
let user = Moralis.User.current();
console.log("new account ethAddress: ", user.get("ethAddress"));

});

Could you teach me how I can close Metamask? This is the only method I can take to open the Sign directly.

It does not change the behavior.

How did you do it? If you add a button that the user needs to click to link accounts, it should close that popup/modal - same for any random click on the page or for any extension, not just MetaMask.

Thanks. I got what you mean by now.