[feature] Programmatically or automatically trigger SIWE sign dialog after failure.
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:
- Automatically trigger SIWE sign the next time modal object is created, simply by looking at result from
SIWEClientMethods.getSession. - Expose a function to call to trigger the sign dialog. I found
Web3ModalSIWEClient.signInfunction, however because the user has not signed the message, the session is empty (no address, no chainId).
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.
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.
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
- 1 on this, or at least expose a function like const { siweSign } = useWeb3Modal() to open modal with sign mode if already connected
@Sam-Newman could you create a ticket for this one? Tagging so I don't forget.
Is there a ticket for this one? I am considering a contribution, because I got a case where this would be the best way.
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>
)