web3modal icon indicating copy to clipboard operation
web3modal copied to clipboard

[feature] Programmatically or automatically trigger SIWE sign dialog after failure.

Open ethan-auroria opened this issue 1 year ago • 7 comments

What problem does this new feature solve?

I have integrated a SIWE flow according to the documentation and found the following problem:

  • If the user signs the message as he should, everything is fine.
  • If the user click Cancel or X at the SIWE sign dialog, it is okay.
  • If user click outside of the SIWE sign dialog to close it, or refresh the page before signing, SIWE flow breaks.

When I say SIWE flow breaks, it means that the next time user visit the page the w3m-button will appear as wallet is connected (it is not wrong) but it will not ask the user to sign the SIWE message.

Describe the solution you'd like

There are 2 possible solutions to this:

  1. Automatically trigger SIWE sign the next time modal object is created, simply by looking at result from SIWEClientMethods.getSession.
  2. Expose a function to call to trigger the sign dialog. I found Web3ModalSIWEClient.signIn function, however because the user has not signed the message, the session is empty (no address, no chainId).

ethan-auroria avatar Jan 22 '24 10:01 ethan-auroria

Here is an update, if I use watchWalletClient to listen for the wallet event, and call Web3ModalSIWEClient.signIn if there is a valid, it does work. So perhaps it is the way to go.

ethan-auroria avatar Jan 22 '24 11:01 ethan-auroria

I'm noticing different behaviour between MetaMask and Coinbase browser extensions. MetaMask works as expected, where it will not trigger SIWE sign in if there is a correct session. Coinbase however triggers the SIWE sign in dialog every time the page is reloaded, even if the session is valid.

ethan-auroria avatar Jan 23 '24 03:01 ethan-auroria

I'm noticing different behaviour between MetaMask and Coinbase browser extensions. MetaMask works as expected, where it will not trigger SIWE sign in if there is a correct session. Coinbase however triggers the SIWE sign in dialog every time the page is reloaded, even if the session is valid.

Having same issue here, but with metamask, I provide a valid session data {address, chainId} but nothing happens

ra-sun-god avatar May 06 '24 22:05 ra-sun-god

  • 1 on this, or at least expose a function like const { siweSign } = useWeb3Modal() to open modal with sign mode if already connected

UTkzhang avatar May 20 '24 16:05 UTkzhang

@Sam-Newman could you create a ticket for this one? Tagging so I don't forget.

glitch-txs avatar Jun 06 '24 07:06 glitch-txs

Is there a ticket for this one? I am considering a contribution, because I got a case where this would be the best way.

vikito755 avatar Jun 21 '24 13:06 vikito755

If anyone finds this and is also having difficulty this is my current solution following this documentation: Edit: it works for Next js.

https://docs.walletconnect.com/appkit/next/core/siwe#getaddressfrommessage

Make sure to set the callbackURL to an existing route:

import { SIWEController } from '@web3modal/siwe';

return ( 
<a onClick={ async () => {await SIWEController.signIn()}} className="inline-flex justify-center items-center py-3 px-5 text-base font-medium text-center text-black rounded-full bg-primary-200 hover:bg-primary-300 hover:text-white">
                    Login
                </a>
)

vikito755 avatar Jun 21 '24 14:06 vikito755