Skip to content

Login with email

To authenticate a user via their email address, use the Privy client's Email handler. This is a two step process:

  1. Send an OTP to the user provided email address.
  2. Verify the OTP sent to the user.

1. Send an OTP to the user's email address

After collecting and validating your users email, send an OTP by calling the SendCode method.

csharp
bool success = await PrivyManager.Instance.Email.SendCode(email);

if (success)
{
	// Prompt user to enter the OTP they received at their email address through your UI
}
else
{
  // There was an error sending an OTP to your user's email
}

2. Authenticate with OTP

The user will then receive an email with a 6-digit OTP. Prompt the user for this OTP within your application, then authenticate the user with the loginWithCode method. As a parameter to this method, pass an object with the following fields:

FieldTypeDescription
emailStringThe user's email address.
codeStringOTP code inputted by the user in your app.
csharp
try
{
    // User will be authenticated if this call is successful
    await PrivyManager.Instance.Email.LoginWithCode(email, code);
}
catch
{
    // If "LoginWithCode" throws an exception, user login was unsuccessful.
    Debug.Log("Error logging user in.");
}

This method will throw an error if:

  • the incorrect OTP code is inputted
  • the network call to authenticate the user fails