Skip to content

Logging users out

To log a user out, use the logout method from the usePrivy hook:

tsx
const {logout} = usePrivy();

Below is an example of a sample logout button for your app:

tsx
import {usePrivy} from '@privy-io/react-auth';

function LogoutButton() {
  const {ready, authenticated, logout} = usePrivy();
  // Disable logout when Privy is not ready or the user is not authenticated
  const disableLogout = !ready || (ready && !authenticated);

  return (
    <button disabled={disableLogout} onClick={logout}>
      Log out
    </button>
  );
}

TIP

You can easily attach callbacks to logout using the new useLogout interface! Read more here.

INFO

If a user has connected a wallet to your site, logging the user out will not disconnect their wallet. Users can only disconnect their wallet from your site through their wallet. Similarly, if a user disconnects their wallet from your site manually, Privy will not automatically log the user out.