Email OTP

Email OTP

#Overview

With Magic, you can use Email one-time codes as an authentication mechanism, giving users a simple way to log in using their emails.

#Compatibility

note

Email OTP as an SDK method is only available with Dedicated Wallet. Refer to the Login UI page for more information.

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
01// Assumes you've initialized a `Magic` instance with a Dedicated Wallet API Key
02const login = async (emailAddress, showUI) => {
03  try {
04    const did = await magic.auth.loginWithEmailOTP({ email: emailAddress, showUI: showUI});
05    console.log(`DID Token: ${did}`);
06
07    const userInfo = await magic.user.getInfo();
08    console.log(`UserInfo: ${userInfo}`);
09
10    // Handle user information as needed
11  } catch {
12    // Handle errors if required!
13  }
14}

#Resources