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] getIsConnected() returns false when user is logged in when called on page load #2163

Open
hcote opened this issue Apr 16, 2024 · 2 comments
Labels
bug Something isn't working needs review

Comments

@hcote
Copy link

hcote commented Apr 16, 2024

Link to minimal reproducible example

https://codesandbox.io/p/sandbox/mystifying-mirzakhani-xqnkt3

Summary

If you want to check if a user is connected to web3modal when the page loads, it returns false even though they are. If you set a timeout and make the call after one second, then it registers that a user is connected.

  const getIsConnected = () => {
    return getWeb3Modal().getIsConnected();
  };

  useEffect(() => {
    console.log("getIsConnected before timeout", getIsConnected()); // returns `false`
    setTimeout(() => {
      console.log("getIsConnected after timeout", getIsConnected()); // returns `true`
    }, 1000);
  }, []);
Screenshot 2024-04-16 at 11 29 52 AM

Is this the expected behavior? Is there an alternative for how to know on page load / modal initialization if a user is connected without using a timeout? (even though the reproducible example above is using react as a quick demonstration, I'm using JS https://docs.walletconnect.com/web3modal/javascript/about)

List of related npm package versions

@web3modal/ethers5@4.1.8
ethers@5.7.2

@hcote hcote added bug Something isn't working needs review labels Apr 16, 2024
@mostafa-rio
Copy link

mostafa-rio commented Apr 23, 2024

I wanted to submit this issue just now. I've tested so many techniques.
the problem is that the wab3modal will start the connection sometimes after the window is loaded. This makes impossible to write Auth Gaurd for routing systems like react router.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working needs review
Projects
None yet
Development

No branches or pull requests

2 participants