web3modal icon indicating copy to clipboard operation
web3modal copied to clipboard

[bug] web3modal/siwe - SIWE does not popup when connecting with wallet

Open 2facedsquid opened this issue 1 year ago • 12 comments

Link to minimal reproducible example

https://github.com/2facedsquid/siwe-test

Summary

When connecting with your injected wallet ( in my case I tested metamask ), the siwe message signing does not pop up, it only pops up when already connected and switching the network or the wallet account.

There is also an error in the console of the browser regarding this endpoint call - https://rpc.walletconnect.com/v1/profile/reverse/{address}?projectId={projectId}

with this response: { "status": "FAILED", "reasons": [ { "field": "address", "description": "No name for address is found" } ] }

I presume this console error is not tied to the @web3modal/siwe integration, since it is also present when siwe is not integrated

List of related npm package versions

Issue was first discovered on this config: "@tanstack/react-query": "^5.40.0", "@web3modal/siwe": "^4.2.3", "@web3modal/wagmi": "^4.2.3", "viem": "^2.13.3", "wagmi": "^2.9.8"

The issue is still happening on this config: "@tanstack/react-query": "^5.45.1", "@web3modal/siwe": "^5.0.2", "@web3modal/wagmi": "^5.0.2", "viem": "^2.15.1", "wagmi": "^2.10.2"

2facedsquid avatar Jun 03 '24 14:06 2facedsquid

Experiencing similar behavior on Vue with versions @web3modal/siwe and @web3modal/wagmi above 4.1.11 Very concerned.

Un173 avatar Jun 17 '24 14:06 Un173

Retested after the 5.0.2 release of web3modal and the issue is still present

2facedsquid avatar Jun 18 '24 16:06 2facedsquid

experiencing similar issue

OladetounJed avatar Jun 23 '24 16:06 OladetounJed

Retested in 5.0.11, issue still present @glitch-txs

2facedsquid avatar Aug 15 '24 10:08 2facedsquid

There is also an error in the console of the browser regarding this endpoint call - https://rpc.walletconnect.com/v1/profile/reverse/{address}?projectId={projectId}

with this response: { "status": "FAILED", "reasons": [ { "field": "address", "description": "No name for address is found" } ] }

I presume this console error is not tied to the @web3modal/siwe integration, since it is also present when siwe is not integrated

This error is not related to siwe and doesn't affect the functionality.

rtomas avatar Aug 15 '24 13:08 rtomas

I cannot reproduce this in our laboratory/reference/test environment: https://dev.lab.web3modal.com/library/wagmi-all/

https://github.com/WalletConnect/web3modal/blob/main/apps/laboratory/src/pages/library/wagmi-all.tsx

chris13524 avatar Aug 15 '24 14:08 chris13524

@2facedsquid

The problem is that you are returning a value whatever the session actually is in SIWE configs:

async function getSession(): Promise<SIWESession> {
  return {
    address: '0x1',
    chainId: 1
  }
}

This is the problem bc in real world examples (like see our laboratory SIWE configs), the getSession is a promise which should be fetching the user's authentication status and not returning a static value like you do. When you return a static value, our modal is detecting the returned object and thinking the user is authenticated and directly closing the SIWE signing view.

@Un173 @OladetounJed Are you following the same approach? Is your issues the same?

enesozturk avatar Aug 15 '24 19:08 enesozturk

@2facedsquid

The problem is that you are returning a value whatever the session actually is in SIWE configs:

async function getSession(): Promise<SIWESession> {
  return {
    address: '0x1',
    chainId: 1
  }
}

This is the problem bc in real world examples (like see our laboratory SIWE configs), the getSession is a promise which should be fetching the user's authentication status and not returning a static value like you do. When you return a static value, our modal is detecting the returned object and thinking the user is authenticated and directly closing the SIWE signing view.

@Un173 @OladetounJed Are you following the same approach? Is your issues the same?

@enesozturk

What is getSession supposed to return when first connecting where the session is not established yet, meaning that no message was signed? I see that it gets called when the wallet connects, even when substituting for null values ( simulating a non existent session ) the modal does not pop up.

The only time the modal does appear tho is when switching networks even with static values. This MRE refers to an integration where we have correct data in the getSession and its the same outcome of siwe sign-in pop up not appearing.

2facedsquid avatar Aug 16 '24 10:08 2facedsquid

@2facedsquid

The problem is that you are returning a value whatever the session actually is in SIWE configs:

async function getSession(): Promise<SIWESession> {
  return {
    address: '0x1',
    chainId: 1
  }
}

This is the problem bc in real world examples (like see our laboratory SIWE configs), the getSession is a promise which should be fetching the user's authentication status and not returning a static value like you do. When you return a static value, our modal is detecting the returned object and thinking the user is authenticated and directly closing the SIWE signing view.

@Un173 @OladetounJed Are you following the same approach? Is your issues the same?

I have encountered this issue as well, and it has persisted for several months without a solution. To troubleshoot why the SIWE modal dialog doesn't pop up, I directly hardcoded the return value in the following function:

async function getSession(): Promise<SIWESession> {
  return null;
}

During multiple tests, I observed that the SIWE dialog didn't appear a few times, but I'm not sure why. I'm using the Next.js framework with the web3modal version 4.2.3.

leecobaby avatar Aug 23 '24 12:08 leecobaby

If possible, I would prefer to know how to manually trigger the SIWE modal dialog. This way, I can display a “Sign Message” button after the wallet is connected to prompt the user to initiate the signature actively, rather than relying on the internal logic of web3modal to handle it automatically. If this feature is not available, could it be considered for future implementation? @enesozturk @2facedsquid

leecobaby avatar Aug 26 '24 01:08 leecobaby

I can display a “Sign Message” button after the wallet is connected to prompt the user to initiate the signature actively

Isn't this what our flow already does?

chris13524 avatar Aug 26 '24 16:08 chris13524

@leecobaby @2facedsquid we recently announced new AppKit. This issue should already been resolved since we did improve bunch of logics including SIWE flows. So I'd suggest you to upgrade to AppKit v1 instead of Web3Modal.

Here is the migration guide for you: https://docs.reown.com/appkit/upgrade/from-w3m-to-reown

enesozturk avatar Sep 23 '24 10:09 enesozturk