Skip to main content

Logging users in

To have your user login to your app, use the login method from the usePrivy hook. When invoked, this method will open the Privy modal and kick off the Privy authentication flow.

From there, users can choose to:

  • login with their wallet, by signing a SIWE challenge first. This will automatically prompt the user to connect their wallet first, if they have not connected one already.
  • login with email, by entering a verification code sent to them
  • login with SMS, by entering a verification code sent to them
  • login with their Google, Twitter, Discord, or Github accounts via the OAuth 2.0 protocol
Sample login flow with MetaMask.

Sample login flow with MetaMask.

As an example, you might attach login as an event handler to a login button in your app:

Example Login Button
import { usePrivy } from '@privy-io/react-auth';

function LoginButton() {
const { login } = usePrivy();
return <button onClick={login}>Log in</button>;
}
tip

Login options can be customized, e.g., whether or not SMS login is enabled for your app. By default, Privy enables email and wallet login options for new apps.

To enable or disable these and other login options for your app, please reach out to [email protected]