Web3Auth modal connect() never returns when the modal is closed without signing in

Issue title: Return null from web3auth.connect() when the user closes the modal without signing in
Describe the question
The @web3auth/modal documentation regarding connect() states that it will return a SafeEventEmitterProvider instance on success and null value on error. This is correct according to what I see in the code and the events listened by the Web3Auth instance (ADAPTER_EVENTS.CONNECTED and ADAPTER_EVENTS.ERRORED).
However when the user closes the modal without signing in, no event is fired and no promise ever resolves until the user opens the modal again and actually tries to login. Multiple events are then fired if he fails or succeeds since the event listeners attached on the first attempt aren't removed.
Steps to Reproduce
Steps to reproduce the behavior:

  1. await web3auth.connect() call
  2. close the modal
  3. see that statements after aren't executed
  4. try to login again
  5. see that all statements are executed at once
    Expected behavior:
    It would make sense to return null from connect() when the modal is closed without any login attempt.
    Platform Details
  • Operating System: MacOS
  • Platform used: Web
  • SDK used: Web (@web3auth/modal)
  • Browser Chrome, Safari
  • Web3Auth Version 4.6.2
    Additional context
    You can wrap the call to connect() in console.log to see that all after statements are triggered when the connect() promise resolves.
    console.log('click connect before');
    const provider = await web3auth.connect();
    console.log('click connect after');


Originally posted by: edouardruiz

Check the discussion at: https://github.com/orgs/Web3Auth/discussions/1366