Connected event not fired after redirect succesfull login

Describe the bug
The connected event is not fired after a successful login redirect using web3auth version 6.1.7 in a Next.js application.

To Reproduce
Steps to reproduce the behavior:

Click connect here.
https://one-grid-git-development-onegrid.vercel.app/rickyrazu
You will be redirected to the external authentication provider (e.g., MetaMask or another Web3 wallet).
Complete the login process and grant necessary permissions.
After successful authentication, you should be redirected back to the application.
Check console => There are logs in it, some times if you go to main page (https://one-grid-git-development-onegrid.vercel.app) and click connect there it works and you see the connected event fired.

1 Like

@lawrence Thanks for your recent communication.

Your issue has been forwarded to our team and we will get back with further updates once more information becomes available.

Looking at the error it looks like you have not specified the web3AuthNetwork parameter during the Web3Auth No-Modal initialization ? I’ll paste a snippet here for your reference on where should it go. Please mention the network you are on Testnet, Mainnet, etc whichever you have setup up on the dashboard should match with the network in your code too.

const web3auth = new Web3AuthNoModal({
  clientId: "", // Get your Client ID from Web3Auth Dashboard
  chainConfig: {
    chainNamespace: CHAIN_NAMESPACES.EIP155,
    chainId: "0x1",
    displayName: "Ethereum Mainnet",
    blockExplorer: "https://etherscan.io",
    ticker: "ETH",
    tickerName: "Ethereum",
    rpcTarget: "https://rpc.ankr.com/eth", // This is the mainnet RPC we have added, please pass on your own endpoint while creating an app
  },
  web3AuthNetwork: "mainnet", // mainnet, aqua,  cyan or testnet
});
1 Like

Incorrect, we have set everything correctly I guess?

const web3AuthInstance = new Web3Auth({
          web3AuthNetwork: `${
            process.env.NEXT_PUBLIC_NODE_ENV === 'production'
              ? 'cyan'
              : 'testnet'
          }`,
          chainConfig: {
            chainNamespace: 'eip155',
            chainId:
              process.env.NEXT_PUBLIC_NODE_ENV === 'production'
                ? '0x89'
                : '0x13881', // hex of 137, polygon mainnet:0x89 polygon testnet: 0x13881
            rpcTarget:
              process.env.NEXT_PUBLIC_NODE_ENV === 'production'
                ? 'https://rpc.ankr    .com/polygon'
                : 'https://rpc-mumbai      .maticvigil.com/',
            // Avoid using public rpcTarget in production.
            // Use services like Infura, Quicknode etc
            displayName: 'Polygon',
            blockExplorer: 'https:    //polygon scan.com', //changed url because not allowed to post more than 2 urls
            ticker: 'MATIC',
            tickerName: 'Matic'
          },
          clientId: `${
            process.env.NEXT_PUBLIC_NODE_ENV === 'production'
              ? process.env.NEXT_PUBLIC_WEB3AUTH_KEY
              : process.env.NEXT_PUBLIC_NODE_ENV === 'development'
              ? process.env.NEXT_PUBLIC_WEB3AUTH_KEY_DEV
              : process.env.NEXT_PUBLIC_NODE_ENV === 'test' &&
                process.env.NEXT_PUBLIC_WEB3AUTH_KEY_PREVIEW
          }`, 
          uiConfig: {
            theme: 'dark',
            appLogo: '/onegrid-logo.png',
            loginMethodsOrder: ['google', 'apple', 'facebook', 'twitter']
          }
        });

Thanks for your reply.

Your Dapp is on Mainnet ?

Our site is on polygon and we have production version, but we are still on 5.x version there

Can you upgrade to the latest version and share your feedback.

I cannot go to latest version because there we have the bug with connect event not firing

So we are staying on 5.x on production because it works there. On testing we are on latest

Ok, I have forwarded your issue to our team and will get back with further updates once more information becomes available.

Hi team, following-up on Francis. we have an important launch this Thursday. Can we jump into a call or chat to quickly explore if the issue is on our side our your side?

@lawrence I have forwarded your request to our team and we are looking into it on priority.

@lawrence @francis.rousseau32 Please have look at this example. I think this fits your use case, and I see that the connected events are getting fired.

We also have the same problem.

The version of web3auth we are using is 6.1.7.

Here is the reproduced code

Please have a look at this example

The latest commit of the example you provided shows downgraded to 5.2.0.

Does this indicate that the CONNECTED event will not fire in the latest version 6.1.7 after all?

@s-nakamatsu That’s not the case. I was aiming to re-create the exact scenario the user was facing, just to see if I get the same issue. The user on 5.x on their prod environment, I was reminded of that later and I downgraded the version and made changes accordingly, hence the commit.

1 Like

I apologize.

The issue that was occurring in my application was due to incorrect code.

Specifically, the timing of calling init() was incorrect.

The problem arose from mistakenly calling init() before the appropriate point, which should have been done after registering the event handler as shown below.

The library version didn’t seem to matter, in my case.

2 Likes