Developers can enable either SMS or WhatsApp, but cannot utilize both. Once your account is
enabled for SMS with your chosen provider, it cannot be switched.
Configuring your application
Through your app’s Privy configuration, you can set the default country code for phone numbers. This is useful if your application primarily serves users from a specific country. The default country can be set in your PrivyProvider, like so:useLoginWithSms hook.To authenticate your users with Privy’s out of the box UIs, check out UI components here.
Send Code
Parameters
string
required
The phone number of the user to log in. Must follow specific formatting conventions (see below).
boolean
Whether to disable the ability to sign up with the phone number.
Returns
Promise<void>
A promise that resolves when the code is sent.
Formatting the phone number
ThesendCode method requires a phoneNumber string param that must follow these formatting conventions:- By default, the implicit phone number country code is +1/US.
- Explicitly prepending a
(+)1to the phone number will still be read as a US phone number. - For non-US phone numbers, append a
+${countryCode}to the beginning of the input value. - Non-numerical values in the string are ignored, except for a leading
+that denotes a custom country code.
Login with Code
Parameters
string
required
The one-time passcode sent to the user’s phone number.
Returns
Promise<void>
A promise that resolves when the user is logged in.
Usage
Tracking Flow State
Track the state of the OTP flow via thestate variable returned by the
useLoginWithSms hook.'initial' | 'error' | 'sending-code' | 'awaiting-code-input' | 'submitting-code' | 'done'
The current state of the OTP flow.
Error | null
The error that occurred during the OTP flow.
Callbacks
You can optionally pass callbacks into theuseLoginWithSms hook to run custom logic after a successful login or to handle errors that occur during the flow.onComplete
Parameters
User
The user object corresponding to the authenticated user.
boolean
Whether the user is a new user or an existing user.
boolean
Whether the user entered the application already authenticated.
LoginMethod | null
The method used by the user to login.
LinkedAccountWithMetadata | null
The account corresponding to the loginMethod used.
onError
Parameters
Error
The error that occurred during the login flow.
Resources
React starter repo
Get started with React and Privy.
Next.js starter repo
Get started with Next.js and Privy.
Whitelabel starter repo
Get started with a whitelabel Privy integration.

