I’m experimenting with Web3Auth in a browser extension, and here’s my setup:
Web3AuthNoModal
import { AuthAdapter } from "@web3auth/auth-adapter"
import { CHAIN_NAMESPACES, WEB3AUTH_NETWORK } from "@web3auth/base"
import { EthereumPrivateKeyProvider } from "@web3auth/ethereum-provider"
import { Web3AuthNoModal } from "@web3auth/no-modal"
import { Web3AuthConnector } from "@web3auth/web3auth-wagmi-connector"
import { type Chain } from "wagmi/chains"
export default function Web3AuthConnectorInstance(chains: Chain[]) {
const chainConfig = {
chainNamespace: CHAIN_NAMESPACES.EIP155,
chainId: "0x" + chains[0].id.toString(16),
rpcTarget: chains[0].rpcUrls.default.http[0],
displayName: chains[0].name,
tickerName: chains[0].nativeCurrency?.name,
ticker: chains[0].nativeCurrency?.symbol,
blockExplorerUrl: chains[0].blockExplorers?.default.url[0] as string
}
const privateKeyProvider = new EthereumPrivateKeyProvider({
config: { chainConfig }
})
const web3auth = new Web3AuthNoModal({
clientId: process.env.PLASMO_PUBLIC_WEB3_AUTH_CLIENT_ID,
web3AuthNetwork: WEB3AUTH_NETWORK.SAPPHIRE_MAINNET,
privateKeyProvider,
uiConfig: {
appName: "Degen.game"
}
})
const authAdapter = new AuthAdapter({})
web3auth.configureAdapter(authAdapter)
return Web3AuthConnector({
web3AuthInstance: web3auth,
loginParams: {
loginProvider: "twitter"
}
})
}
WagmiProvider:
"use client"
import Web3AuthConnectorInstance from "@/lib/config/web3AuthNoModal"
import type { ReactNode } from "react"
import { http } from "viem"
import { createConfig, WagmiProvider as NextWagmiProvider } from "wagmi"
import { base } from "wagmi/chains"
type WagmiProviderProps = {
children: ReactNode
}
export const wagmiConfig = createConfig({
chains: [base],
transports: {
[base.id]: http()
},
connectors: [Web3AuthConnectorInstance([base])]
})
export default function WagmiProvider({ children }: WagmiProviderProps) {
return <NextWagmiProvider config={wagmiConfig}>{children}</NextWagmiProvider>
}
Usage:
import { parseEther } from "viem"
import {
useAccount,
useBalance,
useConnect,
useDisconnect,
useSendTransaction
} from "wagmi"
import { Button } from "./button"
import { Label } from "./label"
export default function Web3AuthNoModal() {
const { connectAsync, connectors } = useConnect()
const { address, isConnected, isConnecting } = useAccount()
const { sendTransactionAsync } = useSendTransaction()
const { disconnectAsync } = useDisconnect()
const account = useAccount()
const balance = useBalance({ address: account.address })
const handleConnect = async () => {
await connectAsync({ connector: connectors[0] })
}
const handleDisconnect = async () => {
await disconnectAsync()
}
const handleSendTransaction = async () => {
console.log("balance", balance)
// to: '0xd2135CfB216b74109775236E36d4b433F1DF507B',
// value: parseEther('0.01'),
const tx = await sendTransactionAsync({
to: account.address,
value: parseEther("0.0000001")
})
console.log("tx", tx)
}
return (
<div>
{!isConnected ? (
<Button onClick={handleConnect}>Connect</Button>
) : (
<Button onClick={handleDisconnect}>Disconnect</Button>
)}
<Label>Is connecting: {isConnecting.toString()}</Label>
<div>Is connected: {isConnected ? "Yes" : "No"}</div>
<div>Address: {address}</div>
<Button onClick={handleSendTransaction}>Send Transaction</Button>
</div>
)
}
Everything works fine, and the user is able to log in successfully. However, after 20–30 minutes (and sometimes up to 2–3 hours), the session gets destroyed, and the user has to log in again. This behavior is quite inconsistent and unusual. Has anyone else encountered this issue or have suggestions for what can be done to maintain the session?
I can share more details if needed. Any help or ideas are appreciated!
Packages versions:
"@web3auth/auth-adapter": "^9.0.2",
"@web3auth/base": "^9.0.2",
"@web3auth/ethereum-provider": "^9.0.2",
"@web3auth/no-modal": "^9.1.0",
"@web3auth/web3auth-wagmi-connector": "^7.0.0",
P.S. I’ve spot that user sometimes becomes sign out after completion of this request:
URL:
https://signer.web3auth.io/api/configuration?project_id={PROJECT_ID}&network=sapphire_mainnet&whitelist=true
Response:
{
"sms_otp_enabled": true,
"wallet_connect_enabled": true,
"key_export_enabled": true,
"wallet_connect_project_id": "{WALLET_CONNECT_PROJECT_ID}",
"whitelist": {
"urls": [
"http://localhost:3000/",
"https://www.viral.games/",
"https://www.viral.games",
"https://viral.games",
"chrome-extension://jhdfgooicalijgeakilpekeoiaajjopd"
],
"signed_urls": {
"http://localhost:3000/": "{SIGNATURE}",
"https://www.viral.games/": "{SIGNATURE}",
"https://www.viral.games": "{SIGNATURE}",
"https://viral.games": "{SIGNATURE}"
"chrome-extension://jhdfgooicalijgeakilpekeoiaajjopd": "{SIGNATURE}"
}
}
}
I’m working with the chrome extension, can’t face similar issues on web.