This was posted to https://privy-developers.slack.com/archives/C059ABLSB47/p1760232442464139 (Privy Developers Slack)
I'm using the latest version (3.3.0) of @privy-io/react-auth.
When I logout() from a existing connection (login() after switching wallet (
- UI:
Could not log in with wallet/Please try connecting again. - Console:
POST https://auth.privy.io/api/v1/siws/authenticate 400 (Bad Request)/Error authenticating sessionin_authenticate - Network: response from
/api/v1/siws/authenticate:{"error":"Invalid SIWS message and/or nonce","code":"invalid_data"}
I think logout() from const { logout } = usePrivy(); does not clear state correctly, since
- prior calls like
/api/v1/siws/initbefore/api/v1/siws/authenticateis using uncleared/outdated address from wallet$A$ , and -
useWalletsfrom@privy-io/react-auth/solanais also returning old state with wallet$A$ .
This is similar to issues like:
- https://privy-developers.slack.com/archives/C059ABLSB47/p1755676679811139
- https://privy-developers.slack.com/archives/C059ABLSB47/p1760092532075009
I got it fixed by adding a temp hack - calling window.solana.disconnect() after logout() (before the new login call).
import { usePrivy } from '@privy-io/react-auth';
export const usePrivyLogout = () => {
const { logout: privyLogout } = usePrivy();
return {
logout: async () => {
await privyLogout();
try {
// @ts-ignore
window.solana.disconnect();
} catch (error) {
console.error(error);
}
},
};
};