loginWithSiwe() throws "User already authenticated" error even after calling logout().
@privy-io/react-auth: ^3.13.0
- Connect wallet A (MetaMask with multiple accounts)
- Click "Login with SIWE" - signs and authenticates with wallet A
- Switch to wallet B in MetaMask
- App automatically detects the account change and:
- Calls
logout() - Attempts
loginWithSiwe()with wallet B
- Calls
loginWithSiwe()should succeed with wallet B- Linked embedded wallet should be available for wallet B
loginWithSiwe() throws: Error: User already authenticated
This happens even though:
logout()was called and completed- The wallet address has changed to wallet B
- We expect a fresh authentication flow
Additionally:
- Cannot get the linked embedded wallet with wallet B
- Replace
YOUR_PRIVY_APP_IDinsrc/main.tsxwith your Privy App ID - Run:
npm install npm run dev
To run on StackBlitz or CodeSandbox:
- Go to https://stackblitz.com or https://codesandbox.io
- Create a new "React (Vite)" project
- Copy the files from this folder
- Replace the Privy App ID
- Run the project
- The app automatically detects wallet account changes via
useEffectwatching the address - When an account change is detected (after SIWE auth), the app:
- Calls
logout()to clear Privy session - Immediately attempts
loginWithSiwe()with the new wallet
- Calls
- The bug occurs: even after
logout()completes,loginWithSiwe()throws "User already authenticated" - The Privy
authenticatedstate may showfalseafter logout, butloginWithSiwestill fails - The linked embedded wallet cannot be obtained for the new wallet (wallet B)