Compatibility

Email OTP is available on all client-side SDKs.

Use Cases

  • Log in and create wallets for end users with a one-time code sent to their email address that they will input for authentication

Usage

You can use Email OTP login by creating a project with our CLI tool and picking ‘Quickstart’ when prompted. Alternatively, you can integrate Email OTP directly into your existing projects using the sample below. Refer to the API documentation for information on how to install and initialize Magic for your existing project. Once you’ve created a Magic instance, log users in using loginWithEmailOTP. In addition to the user’s email address, you can provide a boolean indicating whether or not to show a pre-built modal interface directing the user to enter their one-time passcode. When false, you can implement a custom UI to continue the email OTP flow. Once logged in, you will receive a DID token that can be used with our Admin SDK to verify the user’s information and wallet address on the backend. You can also retrieve the user’s wallet address and email using getInfo for Web/React Native and getMetadata for iOS, Android, and Flutter.
JavaScript
const login = async (emailAddress, showUI) => {
  try {
    const did = await magic.auth.loginWithEmailOTP({ email: emailAddress, showUI: showUI});
    console.log(`DID Token: ${did}`);

    const userInfo = await magic.user.getInfo();
    console.log(`UserInfo: ${userInfo}`);

    // Handle user information as needed
  } catch {
    // Handle errors if required!
  }
}

Resources