reown-com / appkit

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

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

Open ethan-auroria opened 9 months ago

ethan-auroria commented 9 months ago

What problem does this new feature solve?

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

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 commented 9 months ago

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 commented 9 months ago

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.

big-zak commented 6 months ago

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

UTkzhang commented 5 months ago
glitch-txs commented 5 months ago

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

vikito755 commented 4 months ago

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 commented 4 months ago

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>
)