How Does the Logic for Authorized Accounts Work?

Can you also explain how the logic for authorized accounts operates? I encountered an issue while trying to resolve the following problem:

Error: Connection not established. Please call connect() first to request a connection

However, the issue did not consistently reproduce. At times, I granted access to acc1 after the connect function, and it triggered the event of account change as expected:

fuel?.on(this.fuel?.events?.network, this.handleNetworkEvent);

Yet, there were other instances where it did not respond to accounts that had not been granted access beforehand. I am seeking clarification on the correct logic behind authorized accounts.

I have 3 different connectors available at the same time, if it matters

Hi there!

I’m assuming you’ve provided the wrong example, so I’ll be focusing on the account change event.

Do you want the account change event to be triggered each time the user navigates between accounts in the wallet?

As seen in the reference:

This event is triggered when the list of connected accounts to the application change. The callback function receives the account string.

So a non-connected account won’t trigger the event, no matter if the user chose the account in the wallet’s UI.

Let me know if this solves your question :palm_tree:

When the user changes the account to an account that is not allowed to the connection, it will trigger the event with a null value.

This means;

  • Once the users switch an account inside the Wallet
    • If an account is connected to the application, it will trigger the event with the new account address.
    • If the account is not connected to the application, it will trigger the event with a null value.
  • If the user removes the connection inside the Wallet
    • The application will receive an accounts event with the list of accounts currently.

If you try to make any request for the application on an account that is not connected it will throw the error you posted.

Also, another thing to make sure you keep consistently working is to ensure you have only one instance of the const fuel = new Fuel(). More instances would make you need to change the connector on all the instances.

Can you share what method you are calling that is throwing the error?

1 Like