Email OTP Authentication

Email OTP authentication allows you to log in and sign up users using an email address. Your users will receive six-digit code in their inbox which they can enter in your site to complete login.

For setting up an account config, see the Signer Quickstart.

Authenticate a user

1import { signer } from "./signer";
2
3// send the email
4// Promise resolves when the user is fully authenticated (OTP + optional MFA),
5// even if final step completes in another tab/window
6await signer.authenticate({
7 type: "email",
8 emailMode: "otp",
9 email: "[email protected]",
10});
11
12// later once the user has entered the code from their email
13// Promise resolves when the user is fully authenticated (OTP + optional MFA),
14// even if final step completes in another tab/window
15await signer.authenticate({
16 type: "otp",
17 otpCode: "123456",
18});

Track Authentication Status

Use signer.on("statusChanged", callback) and the AlchemySignerStatus enum to respond to OTP/MFA prompts and completion:

1import { signer } from "./signer";
2import { AlchemySignerStatus } from "@account-kit/signer";
3
4signer.on("statusChanged", (status) => {
5 switch (status) {
6 case AlchemySignerStatus.AWAITING_EMAIL_AUTH:
7 // show OTP input UI
8 break;
9 case AlchemySignerStatus.AWAITING_MFA_AUTH:
10 // show TOTP input UI
11 break;
12 case AlchemySignerStatus.CONNECTED:
13 // authentication complete
14 break;
15 }
16});