I'm using Ethers.js to allow users to connect their Metamask wallets to my app. Here's the code that I have:
import { ethers } from "ethers"
async function connect() {
const provider = new ethers.providers.Web3Provider(window.ethereum, "any")
await provider.send("eth_requestAccounts", [])
const signer = provider.getSigner()
const address = await signer.getAddress()
// Always prints the address that I first connected with
console.log(address)
}
The issue is that once I have connected one of my Metamask accounts, then I always get its wallet address even if I switch to another Metamask account and try to connect it as well.
Why is that and how should I fix this?