title: How to check if Metamask is connected after page refreshing
body: <p>My dApp have to connect to MetaMask. There are two rude solutions in the docs: make user to click connect btn every time manually or just pop up connection confirmation after page load. I want to implement the only convenient solution: first time user connect manually by clicking the connect btn and interacting with MetaMask popup and then my dApp detect that connection is still established and use this connection. I can't find the solution, but i saw this in other dApps (<a href="https://capturetheether.com/" rel="nofollow noreferrer">Capture the ether</a> for example) I use:</p>
  <pre><code>import detectEthereumProvider from '@metamask/detect-provider';
  
  const provider = await detectEthereumProvider(); 
  
  if (provider) {
    connect(provider)
  } else {
    // kind of &quot;Install the MetaMask please!&quot;
  }
  
  function connect(provider) {
    // How to check if the connection is here
    if (//connection established) {
      // Show the user connected account address
    } else {
      // Connect
      provider.request({ method: &quot;eth_requestAccounts&quot; })
        .then // some logic
    }
  }
  </code></pre>