Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[bug] Disconnect not persisting and reconnecting on page load #38

Closed
1 task done
sammdec opened this issue Jan 6, 2022 · 6 comments · Fixed by #119
Closed
1 task done

[bug] Disconnect not persisting and reconnecting on page load #38

sammdec opened this issue Jan 6, 2022 · 6 comments · Fixed by #119

Comments

@sammdec
Copy link
Contributor

sammdec commented Jan 6, 2022

Is there an existing issue for this?

  • I have searched the existing issues

Package Version

0.0.17

Current Behavior

Using a Next.js app, Im calling the disconnect function from the useAccount hook. It does disconnect but then after refreshing the page it reconnects again and the account info re-populates

Expected Behavior

I would expect to be disconnected from ym wallet so that I may be able to reconnect again with a different wallet or simply use the site in its disconnected state

Steps To Reproduce

  1. Connect via InjectedConnector -> useAccount becomes populated with data and useConnect returns connected:true.
  2. Press disconnect button which calls the disconnect function. -> useAccount returns empty data as expected and connected: false.
  3. Refresh the page
  4. usAccount becomes populated with data again and connected:true

Anything else?

No response

Edit: It seems as though if I remove autoConnect prop on the provider then it does indeed keep me disconnected however that then means on every refresh I need to reconnect. Ideally I would like connect automatically until I explicitly call disconnect

@sammdec sammdec changed the title [bug] <Disconnect not persisting and reconnecting on page load> [bug] Disconnect not persisting and reconnecting on page load Jan 6, 2022
@iduuck
Copy link

iduuck commented Jan 6, 2022

Seems like a this is a duplicate of #35 (as you noticed yourself in the "Edit").


For the solution: It normally should not prompt every time to connect again through MetaMask, since the connecting only needs to be established once. Could be an option in MetaMask? For me it is only asking once.

@sammdec
Copy link
Contributor Author

sammdec commented Jan 6, 2022

I would expect though that if I call disconnect after reloading it should ask me to connect again and not assume I want to automatically connect with the last used account

@iduuck
Copy link

iduuck commented Jan 6, 2022

I thought it would work with autoConnect? This is a little misleading for you I think.
Having disconnected programatically is like visiting the page, without having connected in the first place. So, if the Provider sees autoConnect it will automatically search for the shim that was injected by Metamask, and try to connect.

If you want the desired behavior, you might want to implement ur own local storage, which is checking whether the user disconnected once in it's lifetime and set the autoConnect prop based on this local storage.

@tmm
Copy link
Member

tmm commented Jan 6, 2022

@sammdec MM (and other injected providers) don't support programmatically disconnecting.

I agree it's confusing to reconnect on page reload, but technically it's the most accurate since the account is still connected to the browser. (wagmi does handle disconnect events coming from connector directly. For example, disconnecting in MM UI.)

That said, you could manage connection status separately in the browser, but you would need to listen and handle different connection events (i.e. disconnecting or switching account directly through MM extensions).

@tmm tmm closed this as completed Jan 6, 2022
@sammdec
Copy link
Contributor Author

sammdec commented Jan 6, 2022

Ah ok yeah that makes sense! Happy to stick what the most default behaviour is in that case

Copy link
Contributor

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 other comments you can create a new discussion.

@github-actions github-actions bot locked and limited conversation to collaborators Jan 19, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants