Privy supports easy onboarding with an out-of-the-box user interface to log users in.The fastest way to integrate Privy is with the Privy login modal. Your application can integrate this modal in just a few lines of code and easily toggle on login methods for your application in the Privy dashboard.You can also design your own login UIs, and integrate with Privy’s authentication APIs to offer a login experience that feels seamless within your application.
You can easily attach callbacks to the login method using the useLogin hook. This allows you to run custom logic when a user successfully logs in or when there’s an error.
Copy
Ask AI
import { useLogin } from '@privy-io/react-auth';function LoginButton() { const { login } = useLogin({ onComplete: ({ user, isNewUser, wasAlreadyAuthenticated, loginMethod, loginAccount }) => { console.log('User logged in successfully', user); console.log('Is new user:', isNewUser); console.log('Was already authenticated:', wasAlreadyAuthenticated); console.log('Login method:', loginMethod); console.log('Login account:', loginAccount); // Navigate to dashboard, show welcome message, etc. }, onError: (error) => { console.error('Login failed', error); // Show error message } }); return <button onClick={login}>Log in</button>;}
Callback that executes when a user completes authentication. If the user is already authenticated when the component mounts, this callback executes immediately. Otherwise, it executes after successful login.
The account used for authentication with type (‘wallet’, ‘email’, ‘phone’, ‘google_oauth’, ‘twitter_oauth’, ‘discord_oauth’, ‘github_oauth’, ‘spotify_oauth’, ‘instagram_oauth’, ‘tiktok_oauth’, ‘linkedin_oauth’, ‘apple_oauth’, ‘line_oauth’, ‘custom_auth’, ‘farcaster’, ‘passkey’).