reown-com / appkit

The full stack toolkit to build onchain app UX
https://reown.com/appkit
Apache License 2.0
4.89k stars 1.38k forks source link

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

Open 2facedsquid opened 4 months ago

2facedsquid commented 4 months ago

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"

linear[bot] commented 4 months ago

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

Un173 commented 3 months ago

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

2facedsquid commented 3 months ago

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

OladetounJed commented 3 months ago

experiencing similar issue

2facedsquid commented 1 month ago

Retested in 5.0.11, issue still present @glitch-txs

rtomas commented 1 month ago

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.

chris13524 commented 1 month ago

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

enesozturk commented 1 month ago

@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?

2facedsquid commented 1 month ago

@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.

leecobaby commented 1 month ago

@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 commented 1 month ago

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

chris13524 commented 1 month ago

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?

enesozturk commented 1 week ago

@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