Persist wagmi session with tKey and MockProvider

Hello,

I’m using tkey and a service worker to implement social login without popup in a react/wagmi app, it’s working nicely.

However the Web3AuthConnector is not usable in that flow and we need to construct a MockConnector from the created private key.

The problem then is that this MockConnector can only be created after receiving a jwt and creating a private key. As far as I understand, we then cannot initialize it and pass it to wagmi’s createConfig. So when coming back to the app, wagmi cannot use the “autoConnect” feature and keep us logged in.

How could that be worked out? Is there a way to persist the log in in that flow?

Thanks

this was an issue was trying to get working but this is how i got it to work

	const wagmiConnected = localStorage.getItem('wagmi.connected');
			const wagmiWallet = localStorage.getItem('wagmi.wallet');
			const isWagmiConnected = wagmiConnected ? JSON.parse(wagmiConnected) : false;
			if (isWagmiConnected && wagmiWallet === '"web3auth"') {
				await connect({
					connector: get(configuredConnectors)[0]
				});
			}

on mount i check if its web3auth connector and if so reconnect it with the connect function from wagmi

1 Like

@oauth Please see above comment

Thanks. Checking the wagmi local storage for “web3auth” would fix it with the Web3AuthConnector flow though, not the MockConnector.

I think it’s more of a problem with wagmi itself, since I’m not finding how to pass a wagmi MockConnector into wagmi’s createConfig.

I was hoping that people using tkey itself and using the flow without popup should have met the same situation.

Thanks!

Solution found, is to store the private key retrieved from the Torus network through tKey, on localStorage (encrypted), and decrypt/pass it to the MockProvider in createConfig. This works.

1 Like

Can you provide the code you used to do this?
Thanks!