Appearance
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>
);
}
INFO
If a user has connected a wallet to your site, **logging the user out will not disconnect their wallet.**Similarly, if a user disconnects their wallet from your site manually, Privy will not automatically log the user out.
For injected wallets (browser extensions), users can only disconnect their wallet from your site through their wallet. For other wallets (e.g. WalletConnect, the Coinbase Smart Wallet), your app can programmatically disconnect a user's wallet by calling the disconnect
method on the wallet's ConnectedWallet
object.