Logging out a user ends their authenticated session, removing their access credentials from the device and requiring them to authenticate again to access protected resources.
To log a user out, use the logout method from the usePrivy hook:
Copy
Ask AI
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> );}
To log a user out, use the logout method from the usePrivy hook:
Copy
Ask AI
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> );}
import PrivySDKclass ProfileViewController: UIViewController { @IBAction func logoutButtonTapped(_ sender: UIButton) { // Check if user is authenticated if let user = privy.user { user.logout() // Navigate back to login screen self.navigationController?.popToRootViewController(animated: true) } }}