Enable email authentication in the Privy
Dashboard before implementing this feature.
To authenticate your users with a one-time passcode (OTP) sent to their email address, use the
useLoginWithEmail
hook.To authenticate your users with Privy’s out of the box UIs, check out UI components here.
Send Code
Parameters
The email address of the user to log in.
Whether to disable the ability to sign up with the email address.
Returns
A promise that resolves when the code is sent.
Login with Code
Parameters
The one-time passcode sent to the user’s email address.
Returns
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
useLoginWithEmail
hook.The current state of the OTP flow.
The error that occurred during the OTP flow.
Callbacks
You can optionally pass callbacks into theuseLoginWithEmail
hook to run custom logic after a successful login or to handle errors that occur during the flow.onComplete
Parameters
The user object corresponding to the authenticated user.
Whether the user is a new user or an existing user.
Whether the user entered the application already authenticated.
The method used by the user to login.
The account corresponding to the loginMethod used.
onError
Parameters
The error that occurred during the login flow.