thirdweb-dev / js

Best in class web3 SDKs for Browser, Node and Mobile apps
https://thirdweb.com
Apache License 2.0
457 stars 373 forks source link

ConnectEmbed SIWE auth state stale after logging out. #4800

Closed jrhe closed 1 month ago

jrhe commented 1 month ago

If you create a ConnectEmbed and connect a wallet, the SIWE functions passed to the auth key are called correctly, with the user being logged into the server.

If you then sign out on the server, by calling your logout endpoint (the logout action in the example repos), and disconnect the wallet, the ConnectEmbed allows you to connect again. When you connect again the SIWE functions passed to auth are not called, as the ConnectEmbed has stale state and thinks that it is already connected to the server.

I have had a look at the implementation of ConnectEmbed and can't quite figure out how to fix it as I'm not familiar enough with tanstack query. One way would be to change the API such that the user has to call useSiweAuth and pass the return value into the ConnectEmbed. The user could then call the doLogout function on the siwe instance.

jnsdls commented 1 month ago

would appreciate the reproduction, however this is likely because we do not refresh the query state in useSiweAuth on manual logout api call - open to suggestions on how to fix it

jrhe commented 1 month ago

Reproduction here: https://github.com/jrhe/thirdweb-createembed-state-bug

The best way I can think of is to extract out the useSiweAuth state so that logout can be called on it directly by other components that need it. I think this is how I'd probably do it if I wasn't using ConnectEmbed but writing my own interface.

Alternatively, there might be a way to stop the state of isLoggedIn being cached.

ninpeng commented 1 month ago

I have same problem.

gregfromstl commented 1 month ago

Hey @jrhe, my apologies this appears to have slipped. I'm working on a fix for this now.

gregfromstl commented 1 month ago

Hey @jrhe @ninpeng, this should be fixed in v5.63.1