Skip to content

Instantly share code, notes, and snippets.

@junhoyeo
Last active October 12, 2025 01:47
Show Gist options
  • Save junhoyeo/7cf818319ef995f98ac8d0a7f246d03d to your computer and use it in GitHub Desktop.
Save junhoyeo/7cf818319ef995f98ac8d0a7f246d03d to your computer and use it in GitHub Desktop.

Problem

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 ($A$) and login() after switching wallet ($B$) on Phantom, I get the following error:

  • 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 session in _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

  1. prior calls like /api/v1/siws/init before /api/v1/siws/authenticate is using uncleared/outdated address from wallet $A$, and
  2. useWallets from @privy-io/react-auth/solana is also returning old state with wallet $A$.

This is similar to issues like:

Solution

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);
      }
    },
  };
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment