The reconnected value of "ADAPTER_EVENTS.CONNECTED" always comes out as true

I tried logging in through “uxmode: redirect”. And I’m trying to call the API through “ADAPTER_EVENTS.CONNECTED” value of reconnected. However, in this mode, the value of reconnected always comes to “true”, even though it is initial. Is there an appropriate section to put the login API through a different lifecycle?
(In the “uxmode: popup”, it returned “false” the first time.)

using @web3auth/core

useEffect(() => {
        const subscribeAuthEvents = (web3auth: Web3AuthCore) => {
            web3auth.on(ADAPTER_EVENTS.CONNECTED, async (data: IWeb3AuthData) => {
                console.log('Yeah!, you are successfully logged in', data);
                setUser(data);
                setWalletProvider(web3auth.provider!);

                if (!data.reconnected) {
                    // LOGIN API REQUEST area [if success. get Accesstoken]
                }
            });

        async function init() {
            try {
                setIsLoading(true);
                const web3AuthInstance = new Web3AuthCore({
                    chainConfig: CHAIN_CONFIG[CHAIN_ENV],
                    clientId,
                    web3AuthNetwork: CHAIN_ENV,
                });
                const openloginAdapter = new OpenloginAdapter({
                    adapterSettings: {
                        clientId,
                        network: CHAIN_ENV,
                        uxMode: 'redirect',
                    },
                });
                web3AuthInstance.configureAdapter(openloginAdapter);
                subscribeAuthEvents(web3AuthInstance);
                setWeb3Auth(web3AuthInstance);

                await web3AuthInstance.init();
            } catch (error) {
                console.error(error);
            } finally {
                setIsLoading(false);
            }
        }
        init();
    }, [setWalletProvider]);

Please use @web3auth/no-modal.

The same issue occurred even though I used @web3auth/no-modal.

I will inform the product team and follow up with you as soon as possible.

1 Like

This is fixed in v6. Pls upgrade

@chai I have the same problem,
versions :
@web3auth/base-provider”: “^6.1.7”,
@web3auth/ethereum-provider”: “^6.1.8”,
@web3auth/metamask-adapter”: “^6.1.7”,
@web3auth/modal”: “^6.1.6”,
@web3auth/openlogin-adapter”: “^6.1.7”,
@web3auth/solana-provider”: “^6.1.8”,
@web3auth/torus-wallet-connector-plugin”: “^6.1.7”,
@web3auth/wallet-connect-v1-adapter”: “^6.1.8”,

any help please

We have released v7 by now. Please upgrade the SDKs to the newest version.

@maharshi I already updated it but it didn’t work for me
let me share my code with you please
“use client”;
import { useEffect, useState } from “react”;

import { Web3Auth } from “@web3auth/modal”;
import { CHAIN_NAMESPACES, CONNECTED_EVENT_DATA, ADAPTER_EVENTS, SafeEventEmitterProvider } from “@web3auth/base”;
import RPC from “…/rpc/web3RPC”;
import { signIn } from “next-auth/react”;
import { EthereumPrivateKeyProvider } from “@web3auth/ethereum-provider”;

import {toogleLogin} from “@/redux/features/web3Slice”;
import {useDispatch} from “react-redux”;
import { AppDispatch, useAppSelector } from “@/redux/store”;
import { OpenloginAdapter } from “@web3auth/openlogin-adapter”;

const clientId = process.env.NEXT_PUBLIC_CLIENT_ID!;

export default function Web3({ …props }) {

const dispatch = useDispatch<AppDispatch>();

const isLoginSignal = useAppSelector((state) => state.web3Reducer.value.login);
const [web3authInstance, setWeb3authInstance] = useState<Web3Auth | null>(null);
const [provider, setProvider] = useState<SafeEventEmitterProvider | null>(null);

useEffect(() => {
    const init = async () => {
        let idToken: any;
        let address: any;
        let userWeb3: any;
        try {
            const chainConfig = {
                chainNamespace: CHAIN_NAMESPACES.EIP155,
                chainId: "0x61",
                rpcTarget: "https://rpc.ankr.com/bsc_testnet_chapel",
                displayName: "Ethereum Mainnet",
                blockExplorer: "https://goerli.etherscan.io",
                ticker: "ETH",
                tickerName: "Ethereum",
              };


            const web3authInstance = new Web3Auth({
                clientId,
                web3AuthNetwork: "testnet",
                chainConfig
            });
      
            const privateKeyProvider = new EthereumPrivateKeyProvider({
                config: { chainConfig },
              });

            const openloginAdapter = new OpenloginAdapter({
                adapterSettings: {
                    network: "testnet",
                    // uxMode: "popup",
                    uxMode: "redirect",
                },
                privateKeyProvider,
              });
              

            web3authInstance.configureAdapter(openloginAdapter);

            await web3authInstance.initModal();

            setProvider(web3authInstance.provider);
            setWeb3authInstance(web3authInstance);

            if (web3authInstance.provider) {
                props.getProviderSignal();
                try {
                    web3authInstance.on(ADAPTER_EVENTS.CONNECTED, async (data: CONNECTED_EVENT_DATA) => {
                        const rpc = new RPC(web3authInstance.provider!);
                        userWeb3 = await web3authInstance.getUserInfo();
                        try {
                            idToken = await web3authInstance.authenticateUser();
                            address = await rpc.getAccounts();
                        }
                        catch (err) {
                            await web3authInstance.logout();
                        }

                        if (userWeb3 && idToken) {
                            const response = await signIn("web3", {
                                user: JSON.stringify(userWeb3),
                                idToken: idToken.idToken,
                                address: address
                            });
                            if (response?.error) {
                                console.log("Error occured:", response);
                                await web3authInstance.logout();
                            } else {
                                console.log('response22222' );
                            }
                        }
                    });
                } catch (error) {
                    console.error('Error during event listener setup:', error);
                }
            } else {
                console.log('noooooooo provieder2');
            };

        } catch (error) {
            console.error('Error during event listener setup:', error);
        }
    };

    init();
}, []);

const login = async () => {
    dispatch(toogleLogin());
    if (!web3authInstance) {
        alert("web3auth not initialized yet");
        return;
    }
    const web3authProvider = await web3authInstance.connect();

    if (web3authProvider) {
        // setProvider(web3authProvider);
        // setIsLoginContext(true);
        // authenticateUser();
    }
};

useEffect(() => {
    if (isLoginSignal) {
        login();
    }
}, [isLoginSignal])
return <></>

}