Record.content.name doesn't change on chainChanged event

ey, first of all I need to ask whether I understand it correctly, that the user Id is being set for the particular chain, and not for every one?
For example if I set the id for the ethereum mainnet, there should be no name when I change to goerli for example, right?

If yes then the issue… the name stays the same for any chain, tho it should be set to null or smth when the chain change… I tried even deleting the cookie mannually tho, doesn’t help

so on chain change I disconnect from the authProvider and connect to the new one again… and I guess it should change the name also?.. what do I do wrong could you tell please, thank you:)

maybe I should use State hook to store the authProvider there and interact with it in the chain change callback?))) ok I’ll try it now

no, doesn’t change anything…:frowning:

it seems like the provider doesn’t change inside of the ethereumAuthProvider… when I change the chain, I still get the names from the prev chain, or still not getting anything, if there weren’t any names in the prev chain

here’s the logs and the code

doesn't change

const getProvider = async () => {
		try {
			disconnect();
			dispatch(setAccountName(''));
			dispatch(setDID(''));
			console.log('chain change event');
			console.log('Browser provider chainId', window.ethereum.chainId);

			if (!window.ethereum) throw new Error("Metamask isn't installed");
			await getChainId();

			const accounts = await window.ethereum.request({ method: 'eth_requestAccounts' });
			const authProvider = new EthereumAuthProvider(window.ethereum, accounts[0]);

			console.log('ethAuthProvider chain', (await authProvider.accountId()).chainId.reference);

			connect(authProvider);
			dispatch(setAccount(accounts[0]));
		} catch (error: any) {
			dispatch(setErrors([error]));

			if (error.code === -32002) await connectTheWallet();
		}
	};
	
useEffect(() => {
			window.ethereum.on('chainChanged', getProvider);
			
			return () => {
			window.ethereum?.removeListener('chainChanged', getProvider);
			}
			
			
},[])

and I use the top-level provider inside of my root nextjs layout… if I try to use it inside of the separate page where I need to read the data from ceramic, I get the no QueryClientProvider error…

so how should I change the chainId inside of the ethAuthProvider? thank you

yeah the ids are different for each network, and as you see the auth provider does not change once it is initialized, its up the consumer to listen/handle for change events (ie address, network) and then create a new auth provider instance on a change

thanks but… of course I’m trying to change it, here’s the code
once the chain change event is emmited my ‘usual’ provider changes, and than the ceramic one should also change, but it doesn’t!!!;(((((

useEffect(() => {
		const connectAuthProvider = async () => {
			try {
				disconnect();
				const accounts = await window.ethereum.request({ method: 'eth_requestAccounts' });
				const authProvider = new EthereumAuthProvider(window.ethereum, accounts[0]);

				console.log('ethAuthProvider chain', (await authProvider.accountId()).chainId.reference);
				await connect(authProvider);

				dispatch(setAccount(accounts[0]));
			} catch (error) {
				dispatch(setErrors([error]));
			}
		};

		if (provider) connectAuthProvider();
		// eslint-disable-next-line react-hooks/exhaustive-deps
	}, [provider]);

I think if you’re using different accounts, you can no longer assume accounts[0], but instead have to check the accounts against the selected chainId. You can then create the EthereumAuthProvider with the correct account.