wagmi icon indicating copy to clipboard operation
wagmi copied to clipboard

Disconnected session cookie not removed after connecting again

Open dengpeng opened this issue 1 year ago • 1 comments

Check existing issues

Describe the bug

When calling disconnect, wagmi would normally store a session cookie like wagmi.io.metamask.disconnected so the page stays disconnected after a refresh.

However, this cookie should be cleared/removed if the user connects again. This removal of the "disconnected" cookie currently only works when the the "connect" call is made on the root / and first level pages (e.g. /foo) but NOT on pages that are deeper (e.g. /bar/qux or /a/b/c).

Link to Minimal Reproducible Example

https://wagmi-bug.vercel.app/

Steps To Reproduce

(Code is available at https://github.com/dengpeng/wagmi-bug)

  • Correct behavior:

    1. Go to https://wagmi-bug.vercel.app/ or https://wagmi-bug.vercel.app/foo.
    2. Connect wallet then disconnect wallet
    3. Now a session cookie wagmi.io.metamask.disconnected is set.
    4. After a successful connect on that page once again, the cookie wagmi.io.metamask.disconnected is removed. ✅
  • Incorrect behavior:

    1. Go to https://wagmi-bug.vercel.app/bar/qux or https://wagmi-bug.vercel.app/a/b/c
    2. Connect wallet then disconnect wallet
    3. Now a session cookie wagmi.io.metamask.disconnected is set.
    4. After a successful connect on that page once again, the cookie wagmi.io.metamask.disconnected is NOT removed. ❌
    5. This will lead to wallet not automatically re-connecting after the page is reloaded. ⚠️

What Wagmi package(s) are you using?

wagmi, @wagmi/core

Wagmi Version

@wagmi/[email protected], [email protected]

Viem Version

2.16.3

TypeScript Version

5

Anything else?

No response

dengpeng avatar Jun 28 '24 17:06 dengpeng

yeah same issue

https://github.com/wevm/wagmi/issues/4073

arunkumar201 avatar Jun 30 '24 04:06 arunkumar201

Yep confirm this issue exists.

My fix for now is to delete wagmi.*.disconnected cookies when you are connected.

evgenyboxer avatar Jul 22 '24 03:07 evgenyboxer

I tried to opt out the storage object in createConfig method. The wagmi.*.disconnected, wagmi.store, etc. are saved in localStorage. Are there any other scenario where these object could be stored? so that it can be handled correctly

redianmf avatar Jul 31 '24 07:07 redianmf

I had a poke at this, it seems setting a different cookie path fixes the issue as cookies with the path / are not recognised on e.g. /a/b/c.

goosewobbler avatar Aug 02 '24 16:08 goosewobbler

This issue has been locked since it has been closed for more than 14 days.

If you found a concrete bug or regression related to it, please open a new bug report with a reproduction against the latest Wagmi version. If you have any questions or comments you can create a new discussion thread.

github-actions[bot] avatar Aug 23 '24 00:08 github-actions[bot]